ujjwalguptaofficial / JsStore

Simplifying IndexedDB with SQL like syntax and promises
http://jsstore.net/
MIT License
858 stars 110 forks source link

Where condition on column not working for 'equal' cases #269

Closed PierreLucB closed 2 years ago

PierreLucB commented 2 years ago

Hello, I can't succeed to retrieve a value in a table while directly filtering the column by his value.

Here is my code :

declare var require: any;

const getWorkerPath = () => {
    if (environment.production == false) {
         return require("file-loader?name=scripts/[name].[hash].js!jsstore/dist/jsstore.worker.js");
    }
    else {
       return require("file-loader?name=scripts/[name].[hash].js!jsstore/dist/jsstore.worker.min.js");
    }
};
const workerPath = getWorkerPath().default;

export const conForTests = new Connection(new Worker(workerPath));

  // Create db with initial table
      conForTests.initDb({
         name: 'DbTests', tables: [{
            name: 'Table1',
            columns: {
               col1: { primaryKey: true, keyPath: ['col1'] }
            }
         }]
      }).then(() => {

         // value for tests
         const col1valeur = '2';

         // Insert the value
         conForTests.insert({ into: 'Table1', values: [{ col1: col1valeur }] })
            .then(res => {
               console.log('Should be 1 : ' + res);

               // Retrieve the value => doesn't works
               conForTests.select({ from: 'Table1', where: { col1: col1valeur } }).then(res => {
                  console.log('value found', res);
               });

               // Retrieve the value with a 'like' operator => works
               conForTests.select({ from: 'Table1', where: { col1: { like: col1valeur } } }).then(res => {
                  console.log('value found 2 ', res);
               });
            });
      })

The where condition isn't working in the first case, I have to use the like operator to filter the values.

Please tell me what am I missing.

Thx

ujjwalguptaofficial commented 2 years ago

is your value stored as number or string ?

PierreLucB commented 2 years ago

It's in string

ujjwalguptaofficial commented 2 years ago

Can't say what's happening, it should work but my guess is there is something wrong with data - may be some space, or other chracters.

Can you provide me some reproducable please ?

PierreLucB commented 2 years ago

the code I provided can works as standalone. The value "2" of the variable col1valeur cannot be found

ujjwalguptaofficial commented 2 years ago

Hey @PierreLucB

I tried in idbstudio for numbers and it is working for me. Screenshot from 2022-06-07 09-03-55 Screenshot from 2022-06-07 09-08-50

I will try your code later.

ujjwalguptaofficial commented 2 years ago

@PierreLucB try removing the keypath and it should work. Let me know if it does not.

PierreLucB commented 2 years ago

Honestly after few days working with jsstore, I just abandoned and made my own solution.

ujjwalguptaofficial commented 2 years ago

yeah that's cool :).