by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Ujjwal Gupta
    @ujjwalguptaofficial
    ok looking into this
    Ghost
    @ghost~5e1340abd73408ce4fd5da17

    @ujjwalguptaofficial ,

    I am working on a progressive web application project.

    The main thread, inspection.js, starts a worker, inspectionworker.js, and detects when the user is offline or online. When online, the information a user submits is sent directly to the server. When offline, the data is sent to the web worker for storing in the local database until the user is back online. Once online again, the service worker is responsible for sending all the offline data to the server while the main thread is available for new inspections.

    This was working when establishing a connection to the database using the JsStoreWorker directly. But after broader testing, I found out it was only working in Firefox and Chrome on my Mac. It failed in Safari and on mobile devices, saying the JsStoreWorker could not be found.

    I thought this problem might be solved by including the JsStoreWorker.js as a script but not using it directly in creating the connection objects, but it's not working. As a test, when I try to add a record and I have not imported the JsStoreWorker.js, an error is thrown saying JsStoreWorker cannot be found. When I import the script and try to add a record, the add fails silently.

    Based on the behavior/problem being similar in both cases, I am wondering if perhaps I cannot use JsStore in a web worker?

    Thanks in advance for you help!!

    Marion PERRIER
    @hist0plasma_gitlab
    Hi !
    Is it possible to use JsStore without any installation to do for the user ? :)
    (also serverless)
    Ujjwal Gupta
    @ujjwalguptaofficial
    JsStore is a client side library which works on top of indexeddb , its not a service. I am not sure what you are asking but hope this helps you to understand.
    PWTycoon
    @PWTycoon
    Is multi-entry basically the equivalent of storing an array? If so, can I perform array operations on a column? (push, indexOf, ...)
    Ujjwal Gupta
    @ujjwalguptaofficial

    You can store array without multientry, but element inside array wont be indexed so not searchable.

    multiEntry allows you to search elements present inside an array.

    JsStore supports only push functionality for now , check here - https://jsstore.net/tutorial/update-with-operators/

    But you are free to use whatever operation you want to do on array by retrieving the value using select api.

    Mike Talbot
    @mike_talbot_twitter
    Hi, I see that the Github page is showing no support for Edge and IE11 - is that right or is it a temporary thing that has the tests failing?
    Ujjwal Gupta
    @ujjwalguptaofficial
    temporary things - some test cases failing due to es6 code or some config. I have linux so not able to see what's happening.
    Mike Talbot
    @mike_talbot_twitter
    Many thanks! Looking forward to working with JsStore then!
    adamsbc
    @adamsbc
    I keep getting this error. ReferenceError: JsStoreWorker is not defined. I'm using JsStore in node js

    const JsStore = require('jsstore');
    var dbName ='client_db';
    function getDbSchema() {
    var tblTest = {
    name: 'Test',
    columns: {
    id:{ primaryKey: true, autoIncrement: true },
    title: { notNull: false, dataType: "string" },
    description: { notNull: false, dataType: "string" },
    type : { notNull: false, dataType: "string" },
    path : { notNull: false, dataType: "string" },
    createdBy : { notNull: false, dataType: "number" },
    groupID : { notNull: false, dataType: "number" },
    },
    name: "Group",
    columns: {
    id:{primaryKey: true, autoIncrement: true },
    name: { notNull: false, dataType: "string" },
    }
    };

    var db = {
    name: client_db,
    tables: [tblTest]
    }
    return db;
    }

    var client_connection = new JsStore.Connection();
    async function initJsStore() {
    var database = getDbSchema();
    const isDbCreated = await client_connection.initDb(database);
    if(isDbCreated===true){
    console.log("db created");
    // here you can prefill database with some data
    }
    else {
    console.log("db opened");
    }
    }

    Ujjwal Gupta
    @ujjwalguptaofficial
    @adamsbc You gotta include jsstore worker file . Check out this example - https://github.com/ujjwalguptaofficial/jsstore-examples/tree/master/without_web_worker
    adamsbc
    @adamsbc
    I have the Jsstore.worker.js in the same directory
    Ujjwal Gupta
    @ujjwalguptaofficial
    @adamsbc you need to include the script in your html file.
    adlf
    @adlf

    Hello. I'm getting this error.

    ReferenceError: JsStoreWorker is not defined

    On the top of my script, i'm importing jsstore like so

    import * as JsStore from 'jsstore';

    But as I understand this uses JsStoreWorker which is not defined in the module and since it can't find it it throws an error.

    I tried yarn add JsStoreWorker but no luck

    Stanislaw Grin
    @stanislav-grin

    Hi,
    faced an issue when doing select with 'not equal' condition ('!='). Seems like where clause is mutated when specify not equal condition and been replaced by '>'. Here is snippet that reproduces it for me:

        const where = { bio: { '!=': '' } }
    
        console.log('where: ', JSON.stringify(where)) // where:  {"bio":{"!=":""}}
    
        const records = await idbConnection.select({
          from: tableName,
          where
        })
    
        console.log('where: ', JSON.stringify(where)) // where:  {"bio":{">":""}}

    As you can see, there is no modifications of 'where' object from my side, but I constantly getting this result: '!=' is replaced by '>'.
    Any help/ideas would be much appreciated. Thanks!

    Ujjwal Gupta
    @ujjwalguptaofficial
    @stanislav-grin yes it is mutated to '>' or '<' query for faster data fetching using indexes. Do you see any problem with it ?
    Stanislaw Grin
    @stanislav-grin
    Yes, I have one of three objects with bio: null and receive only one object with bio that is not empty. SQL alternative would be 'where bio is not null'.
    And if I have 4 objects with 'age' column, values are 25, 27, 29, 30 select where age != 27 then I receiving only those objects where age > 27. Morover, (just checked it once again) - only one object is received (expected 3).
    Stanislaw Grin
    @stanislav-grin
    yes, in idbStudio it works as excepted, but not when running locally on my machine. I use latest version which is 3.7.3
    Could it be that idbStudio uses older version or something else that might affect on this?
    Ujjwal Gupta
    @ujjwalguptaofficial

    Can't say really what's happening, i just updated idbstudio with latest version of jsstore & it worked well.

    i will suggest you to check with different version of query like using regex , using or query with less than & greater than - and compare results. Use Idbstudio for debugging query.

    Stanislaw Grin
    @stanislav-grin
    I tried all other approachs (including regex, gt, ls, etc) and it works well.
    Ok, thanks. Then I'll try to create a small reproducible sample project today (in a couple of hours) and let you know it, if this behavior still persists, I'll share it with you. Thanks once again.
    Stanislaw Grin
    @stanislav-grin
    Seems column with primary key is required to be present for this to work correctly, does not it?
    Ujjwal Gupta
    @ujjwalguptaofficial
    yes, otherwise its not possible to compare different rows of records, Primary key is used to determine uniqueness of a row.
    Stanislaw Grin
    @stanislav-grin

    Hi @ujjwalguptaofficial , it's me again,

    could you please shed some light on how to get records in which a certain field (say, date_time) is null. I know that Boolean values are not valid in the indexedDB, and they can be replaced with a string representation or a numeric (0/1), but what if the column type is not Boolean and the data in it can be null? It is not possible to write an empty string instead of this value, say for the date_time column type. Then how could I select records where someColumn is null?

    Ujjwal Gupta
    @ujjwalguptaofficial
    @stanislav-grin , you can't query for null to, its same as boolean value. Read here - https://stackoverflow.com/questions/52749199/jsstore-search-for-a-null-value
    Stanislaw Grin
    @stanislav-grin
    Ok, but is any workaround on how to store data in non-boolean columns where some values could be null? I can't insert 0/1 or string 'null' into date_time and number columns. Values are just not always exists.
    Ujjwal Gupta
    @ujjwalguptaofficial

    @stanislav-grin since indexeddb is no sql database, you can store anything. JsStore by default check for data type when inserting data, use skipDataCheck for not checking data.

    Depends upon your logic, you can choose a very old date & consider it as null.

    Stanislaw Grin
    @stanislav-grin
    Hi! Could you please advise how to add new tables in existing DB? I tried something like the following, but it works incorrect for me. I beleive there should be more obvious way to do it:
    const [dbVersion, dbSchema] = await Promise.all([
      idbConnection.getDbVersion(DBName),
      idbConnection.getDbSchema(DBName)
    ])
    
    const dbTables = dbSchema ? dbSchema.tables : []
    const indexOfTable = dbTables.findIndex(table => table.name === newTableName)
    
    const table = {
      name      : newTableName,
      columns   : columns,
      version   : dbVersion + 1
    }
    
    if (indexOfTable !== -1) {
      dbTables[indexOfTable] = table
    } else {
      dbTables.push(table)
    }
    
    await idbConnection.initDb({
      name: DBName,
      tables
    })
    Ujjwal Gupta
    @ujjwalguptaofficial
    seems good to me, please debug and see if everything is being executed. initDb api returns boolean - true means db is created/updated , and false means only opened.
    Stanislaw Grin
    @stanislav-grin
    Found a way to correctly add a table. The fact is that when you get the database schema (getDbSchema method), the “column” field is returned as an array of objects, while when creating a table, the columns must be specified as an object, where the key is the column name and the value is its description. It is also necessary to upgrade the version for all existing tables so that the database saves the specified primary key. For anyone who is interested, here is a sample of my code. It is rather cumbersome, but unfortunately, there is no other option to add a table yet. It would be great to add this API to the library and hide all the additional logic under the hood.
    async function addTable(tableName, columns) {
      const [dbVersion, dbSchema] = await Promise.all([
        idbConnection.getDbVersion(DBName),
        idbConnection.getDbSchema(DBName)
      ])
    
      const dbTables = dbSchema ? dbSchema.tables : []
      const nextVersion = dbVersion + 1 // To say DB is must to update schema/tables, version should be incremented
    
      // transform existing table's columns from array to object
      // [{ name: 'columnName', dataType: 'string' }, ...] => { columnName: { dataType: 'string' }, ...}
      dbTables.forEach(table => {
        table.columns = table.columns.reduce((cols, column) => ({
          ...cols,
          [column.name]: column
        }), {})
    
        table.version = nextVersion // without this primary key of table will be lost
      })
    
      const indexOfTable = dbTables.findIndex(table => table.name === tableName)
    
      const table = {
        name      : tableName,
        columns   : columns,
        version   : nextVersion,
        primaryKey: 'your_primary_column_name' // here is your own primary key
      }
    
      if (indexOfTable !== -1) {
        dbTables[indexOfTable] = table // table exists, override it
      } else {
        dbTables.push(table) // table not exists yet, add new one
      }
    
      await idbConnection.initDb({
        name: DBName,
        tables
      })
    }
    Stanislaw Grin
    @stanislav-grin

    One more question please. I doing next scenario:

    1. init some table and insert data into it. Works fine
    2. clear table data using idbConnection.clear(tableName) method.
    3. Trying to insert data into this table again - and no success. All db's methods afther that (e.g. getDbSchema) return a promise with eternal 'pending' status.

    Is this a bug or am I missed something?

    Ujjwal Gupta
    @ujjwalguptaofficial
    @stanislav-grin seems like bug, please add an issue . Alternatively - you can try : remove api without where.
    Also i will take a look at what you have suggested above for db schema api.
    Stanislaw Grin
    @stanislav-grin
    Unfortunately, my example above (about adding a table) is also not quite correct. The fact is that in order to save the primary key of existing tables, it is necessary to upgrade their version. But in turn, this leads to data loss in these tables :( I'm again at a dead end ...
    Ujjwal Gupta
    @ujjwalguptaofficial

    How about this -

    1. Initialize your schema as you are doing now
    2. Get db version - let's say 1 in case
    3. If version ==1 , i want to update db schema but don't want to loose my data
    4. Get Table data and store it in a memory
    5. Upgrade schema - initialize db with new db schema
    6. Insert data from memory from step 4 into new table

    @stanislav-grin see if this works. Please test properly before deploying .

    Ujjwal Gupta
    @ujjwalguptaofficial
    Also explicitly define your new db schema, do not modify existing one. So you will have two db schema. Keeping db schema clear will help you to iterate what was changed from old to new.
    Stanislaw Grin
    @stanislav-grin
    Hi @ujjwalguptaofficial , thanks for reply!
    I was thinking about keeping data in memory and insert it afterwards, but in my case it's not a best solution. What I'm doing now - is a library for offline support. The idea is that my clients working with remote mysql db, and they should have an abillity to "go offline". When they go offline, they define which tables and dataset they want to keep locally and then work with these tables just like with remote DB, using the same API. When internet connection established or when they manually switched to online mode, their local data should be synced with remote DB - all creted, updated and removed objects will be reflected in remote DB and if needed, all fresh data from remote DB will be retrieved to local DB. Also if user choose a 'store all' policy, it means that when he doing any request to remote DB, response data will be kept in local DB (if table not exist yet, than first create it and then insert retrieved data, othervise just insert data - upsert existing objects and new ones). This is all in general words, use-cases may be more complex. So, there may be a chance that user wants to keep a lot of tables and data in local DB and thus keeping it in memory while creating a new table in DB may lead to performance problems and unexpected errors during these operations... Your library is perfectly fit my requirements, and I almost finished all this logic, execpt this one case
    Ujjwal Gupta
    @ujjwalguptaofficial

    Got it

    I am also not sure what will be best way as data will be always lost when trying to upgrade db schema - its IndexedDb limitation :(.

    How about creating multiple tables with some kinda of versioning. Let's say when db is created first time & later user wants to change db schema then you create another table and then move data from old table to new table (based on some logic) and then clear old table. This way you will have multiple tables for one actual table. You will also have to store versioning data, so that you can create multiple version table.

    Not sure if this is the best solution but this will work at least :).

    pankajminda
    @pankajminda
    Hi @ujjwalguptaofficial , Can we join 2 tables which have id as string columns
    Ujjwal Gupta
    @ujjwalguptaofficial
    @pankajminda yes
    Stanislaw Grin
    @stanislav-grin
    Hi @ujjwalguptaofficial, thanks for your response. I was thinking about what you have write, but not quite understand how to implement such logic without keeping in-memory data before adding new table.
    Is it really impossible to do in any way so that you can add new tables to the database without losing data in existing ones? This is the only thing that stopped me. If it is absolutely impossible to add such API to the library, it remains to implement all the logic using local storage. And it's disappointing. I’m aware about performance and storage limitations aspects, but without ‘add table API’ this seems the only way to workaround it...
    Ujjwal Gupta
    @ujjwalguptaofficial

    @stanislav-grin as i said - its indexeddb limitation for good reason. But i think

    what you want is achievable based on some dynamic logic -

    Let's say you have a table employee, now since you want multiple version of employee - we will do this

    We will create another table which contains version changes, so for first time user let's say employee table version is 1.

    and table name will be - employee_v1

    now user wants to change employee table structure, so now we will add another table to db schema which will be - employee_v2.

    since you have added a table, employee_v1 table data won't be lost . Now you can select from old table and insert into new table based on what data employee_v2 table needs from old table & clear old table record(depends upon you).

    But again its very tricky. You gotta think through it, i am only giving you a headstart.

    Ronaldo Gomes Carvalho
    @ronaldogomescarvalho
    how to get multiple checkbox value
    Antonio Blanco Barreda
    @ablancobarreda_twitter
    good afternoon! somebody can give me a tutorial of JsStore. Thanks
    Ujjwal Gupta
    @ujjwalguptaofficial
    @ablancobarreda_twitter what tutorial do you need ? there is already get started tutorial - https://jsstore.net/tutorial/get-started/ & examples repo- https://github.com/ujjwalguptaofficial/jsstore-examples
    AgroXXI
    @agroXXI_news_twitter
    Hi! I have a difficult question. How to implement an analog of SQL fulltext search using js store. Example, SELECT * FROM table WHERE MATCH(title, indexing) AGAINST ('>\"keytext1\" <(keytext2 keytext3)' IN BOOLEAN MODE) > 0
    ORDER BY ('>\"keytext1\" <(keytext2 keytext3)' IN BOOLEAN MODE) DESC It's a matter of life and death for my web app. =(