Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    richard rose
    @manEatingFish_twitter
    Is this correct behaviour fro IndexedDB? if so is there anything I can do to make the the where and order occur before the skip and limit is applied?
    Let me know if you can regenerate.
    akhilponnala
    @akhilponnala
    Hi guys,
    How can we use union.
    Ujjwal Gupta
    @ujjwalguptaofficial

    Hi @akhilponnala

    right now, jsstore doesn't support union. Please add an issue on jsstore github page.

    Thanks.

    akhilponnala
    @akhilponnala
    Hi @ujjwalguptaofficial
    Please help me in preparing alternate query to union.
    Thanks.
    Ujjwal Gupta
    @ujjwalguptaofficial
    ok sure, looking into this.
    Ujjwal Gupta
    @ujjwalguptaofficial
    @akhilponnala - added the union api. Have a look at - https://jsstore.net/tutorial/union/
    akhilponnala
    @akhilponnala
    Hi @ujjwalguptaofficial
    Thank you for your support.
    akhilponnala
    @akhilponnala
    Hi @ujjwalguptaofficial ,
    How can we implement MYSQL CASE function using jsstore.
    for example:
    SELECT CustomerName, City, Country
    FROM Customers
    ORDER BY
    (CASE
    WHEN City IS NULL THEN Country
    ELSE City
    END);
    Please suggest us on above if there is any altenative method using jsstore
    Hi @ujjwalguptaofficial ,
    please suggest on specifying the default values using jsstore in table creation
    Ujjwal Gupta
    @ujjwalguptaofficial

    Hi

    Jsstore doesn't have this functionality yet. Please add an issue on github. I will take it from there. Thanks.

    akhilponnala
    @akhilponnala
    Hi @ujjwalguptaofficial ,
    Thank you.
    I have added issue on github. Please help us on implementing above.
    Thank you.
    akhilponnala
    @akhilponnala
    Hi @ujjwalguptaofficial ,
    Can we use 'Case' funtionality with group by clause.
    Can we apply then value from results dynamically.
    For example :
    select count(*) as s_count,d3.des as des1,(CASE d.des WHEN 'Other' THEN e.v_other ELSE d.des END) as making ,(CASE d1.des WHEN 'Other' THEN e.v_other ELSE d1.des END) as desc ,(CASE d.des WHEN 'Other' THEN e.v_other ELSE d.des END) as maker ,(CASE d1.des WHEN 'Other' THEN e.v_other ELSE d1.des END) as module ,sign.opId as oper_id from val as e inner join drop as d on d.drop_id=e.v_make inner join drop as d1 on d1.drop_id=e.v_model inner join sign as s on s.sig_id=e.sig_id inner join drop as d3 on d3.drop_id=s.oper_id group by making, module,oper_id order by oper_id
    Please help us on implementing above.
    Thank you.
    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.