ujjwalguptaofficial / JsStore

A complete IndexedDB wrapper with SQL like syntax.
http://jsstore.net/
MIT License
849 stars 109 forks source link

"Where" clause with more than one column in "or" operator doesn't work properly #297

Closed alisabrigok closed 1 year ago

alisabrigok commented 1 year ago

"Where" clause with more than one column in "or" operator doesn't seem to work properly.

Below can be tried using IDBStudio with the existing Demo database:

The below query shows 29 results, which correct.

{
    select({
        from: 'Orders',
        where: {
            employeeId: 6,
            or: {
                employeeId: 5,
            },
        }
    })
}

But below shows precisely the same result 29, which is incorrect. Because I am expecting to see the orders where employeeId is 6 or 3 or 1 or 4 or 5. Below shows me the exact same results as above, employeeId is 6 or 5.

{
    select({
        from: 'Orders',
        where: {
            employeeId: 6,
            or: {
                employeeId: 3,
                employeeId: 1,
                employeeId: 4,
                employeeId: 5
            },

        }
    })
}

The issue exists even if you try to use different operators under "or". For instance, the below query should also take the value "3" into consideration but instead, it also returns 29 as above.

{
    select({
        from: 'Orders',
        where: {
            employeeId: 6,
            or: {
                employeeId: {
                    in: [3]
                },
                employeeId: {
                    in: [5]
                }
            },

        }
    })
}

Also, the issue isn't limited to the "select" query. It exists for "count" as well.

Below shows 29.

{
    count({
        from: 'Orders',
        where: {
            employeeId: 6,
            or: {
                employeeId: 3,
                employeeId: 1,
                employeeId: 4,
                employeeId: 5
            },

        }
    })
}

It seems while querying with the "or" operator, only the last key-value pair in the object is taken into consideration right now, others are ignored.

I hope the description is clear enough, thanks for the great work.

ujjwalguptaofficial commented 1 year ago

will take a look. Thanks for such a well description.

ujjwalguptaofficial commented 1 year ago

@alisabrigok - when you initialize an object with same key multiple times - only last one is taken into consideration by javascript. Its javascript not jsstore.

check below screenshot

image

I wonder why would you try something like that way - when you can use in query for multiple values with same column.

e.g -

 select({
        from: 'Orders',
        where: {
            employeeId: {
                 in:[1,2,3,4,5]
           }
        }
    })
alisabrigok commented 1 year ago

Ah, that's silly of me. I was actually having this problem in my app with totally different columns, therefore with different keys. But for the sake of reproducibility, I wanted to use IDBStudio and didn't realize at all that what I was doing already doesn't make sense.

Tested a couple of fields with the "or" operator in IDBStudio in a non-silly way, and all seems to be working fine.

Sorry for taking your time. Closing the issue, if I can reproduce what I am experiencing, I will comment and open it again.