ujjwalguptaofficial / JsStore

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

Simulate NOT IN operator #38

Closed ghost closed 6 years ago

ghost commented 6 years ago

Hi I'm having difficulties simulating the NOT IN (...) operation.

As there is no negation operator for In, I thought that an AND operation with the same field would be fine, but it produces an error instead. This is the code I'm playing with:

    {
            From: 'Job',
            Where: [{
              dateExpiryStart: { '>': 0 },
              state: { '!=': 'Concluded' }
            }, {
              state: { '!=': 'WaitPickup' }
            }
            ],
    };

Any suggestion?

ujjwalguptaofficial commented 6 years ago

What's the error message ? Also Can you write your query in sql, so that I can simulate what will be equivalent query in jsstore.

ghost commented 6 years ago

No error, there just isn't a syntax that makes it possible in the documentation.

SELECT * FROM Job WHERE dateExpiryStart > 0 AND state NOT IN ('Concluded', 'WaitPickup)

Also I'm having problem identifying records with empty fields, but I'm still experimenting here

ujjwalguptaofficial commented 6 years ago

Well that is a kinda of something i have never tried - lets see if this works.

select({
    From:'Job',
    Where:[{
      dateExpiryStart :{'>':0}  
    },{
        state:{
            In:{
                '!=':['Concluded','WaitPickup']
            }
        }
    }]
})

or

select({
    From:'Job',
    Where:[{
      dateExpiryStart :{'>':0}  
    },{
        state:{
            '!=':{
                In:['Concluded','WaitPickup']
            }
        }
    }]
})

Let me know which one works.

ghost commented 6 years ago

Now, I figured out the problem with the empty fields, I'll post code updated for this requirement.

The first code:

Where:[{
              dateExpiryStart :{ '!=': null }
            },{
              state:{
                In:{
                  '!=':['Concluded','WaitPickup']
                }
              }
            }]

produces an error:

DOMException: Failed to execute 'only' on 'IDBKeyRange': The parameter is not a valid key.
    at n.r.getKeyRange (http://localhost:4200/scripts.bundle.js:8:18799)
    at n.t.executeWhereLogic (http://localhost:4200/scripts.bundle.js:8:48331)
    at n.goToWhereLogic (http://localhost:4200/scripts.bundle.js:8:21028)
    at n.processWhere (http://localhost:4200/scripts.bundle.js:8:60581)
    at n.<anonymous> (http://localhost:4200/scripts.bundle.js:8:60082)
    at n.processWhereArrayQry (http://localhost:4200/scripts.bundle.js:8:60109)
    at n.execute (http://localhost:4200/scripts.bundle.js:8:58971)
    at Main.select (http://localhost:4200/scripts.bundle.js:8:33158)
    at Main.executeLogic (http://localhost:4200/scripts.bundle.js:8:31322)
    at Main.checkConnectionAndExecuteLogic (http://localhost:4200/scripts.bundle.js:8:30221)

which I get whenever I try to put arrays in WHERE clauses.

ghost commented 6 years ago

Also the second one produces the same error, for the same reason I think, so we can't really verify wether any is good or not until we solve that.

ujjwalguptaofficial commented 6 years ago

yeah i have not tested this query. I will add this.

Thanks

ujjwalguptaofficial commented 6 years ago

I was just guessing if this feature is there, equivalent qry will be something like that.

ghost commented 6 years ago

You mean the Where: [], right? In order to use the last dev build (so I can also perform some testing), what should I do? I also see that you're working on a v2.0, should I use that?

ujjwalguptaofficial commented 6 years ago

Yeah you can use the version2 But its not completed yet - need to create docs, some testing etc. But yeah if you will start using, it will be great for me. You can let me know if there is any issue, so that I can fix it before publishing v2.

V2 has some little changes in syntax, and the way it is worked. So until i update the docs, it may be little tough to use. I have updated the examples folder, so you can figure it out - How to use.

Thanks

ujjwalguptaofficial commented 6 years ago

@Mc128k - can you try this query :

{
    from: 'Job',
    where: [{
        dateExpiryStart: {
            '>': 0
        },
        state: {
            '!=': 'Concluded'
        }
    }, {
        state: {
            '!=': 'WaitPickup'
        }
    }],
};

I know you have tried it before, but there was some fixes in 2.0.5 . So it should work now. Let me know.

Thanks

ujjwalguptaofficial commented 6 years ago

I think - issue is still there. I was trying to produce and found the issue. I will fix it in next release.

Thanks

ghost commented 6 years ago

Yes, I found another selection issue after this, but I'll wait for the next release before posting

ujjwalguptaofficial commented 6 years ago

This issue has been resolved . Here is the idbstudio link - https://ujjwalguptaofficial.github.io/idbstudio/?query=select(%7B%0A%20%20%20%20from:%27Employees%27,%0A%20%20%20%20where:%20%5B%7B%0A%20%20%20%20%20%20notes:%20%7B%27like%27:%20%27%25from%25%27%7D,%0A%20%20%20%20%20%20state:%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%27!=%27:%20%27Concluded%27%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D,%20%7B%0A%20%20%20%20%20%20%20%20state:%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%27!=%27:%20%27WaitPickup%27%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%5D%0A%7D)&db=Demo

@Mc128k - let me know .

Thanks

ujjwalguptaofficial commented 6 years ago

@Mc128k - Please let me know another selection issue that you found. If the issue is not related to current issue then fire another issue.

ujjwalguptaofficial commented 6 years ago

@Mc128k - are we good on this. Can you close the issue if everything good ?

Thanks

ujjwalguptaofficial commented 6 years ago

Closing.

rushi253095 commented 5 years ago

@Mc128k - can you try this query :

{
    from: 'Job',
    where: [{
        dateExpiryStart: {
            '>': 0
        },
        state: {
            '!=': 'Concluded'
        }
    }, {
        state: {
            '!=': 'WaitPickup'
        }
    }],
};

I know you have tried it before, but there was some fixes in 2.0.5 . So it should work now. Let me know.

Thanks

It will work fine