ujjwalguptaofficial / JsStore

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

Issue with or'd like conditions #203

Closed bralax closed 3 years ago

bralax commented 3 years ago

I have been having weird results when trying to use multiple or conditions together. For example:

const query = {
            from: 'list',
            where: {
                name: {
                    like: "%"+param+"%"
                }
            }

Leads to a list of four items in this table that match the query. However if I add in an or statement:

const query = {
            from: 'list',
            where: {
                name: {
                    like: "%"+param+"%"
                },
                or: {
                    id: {
                        like: "%"+param+"%"
                    }
                }
            }

I always get 1 item. Given that the first query results in 4, this one should have at least as many. As a test, I added even more or'd conditions of a similar form and I always get only 1 result.

ujjwalguptaofficial commented 3 years ago

@bralax I am not able to reproduce. Here is what i tried - https://ujjwalguptaofficial.github.io/idbstudio/?db=Demo&query=var%20param%20%3D%20%22the%22%3B%0Aselect(%7B%0A%20%20%20%20from%3A%20'Customers'%2C%0A%20%20%20%20where%3A%20%7B%0A%20%20%20%20%20%20%20%20customerName%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20like%3A%20%22%25%22%20%2B%20param%20%2B%20%22%25%22%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20or%3A%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20customerId%3A%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20like%3A%22%25%22%20%2B%20param%20%2B%20%22%25%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D)

Could you give me something reproducable ?

ujjwalguptaofficial commented 3 years ago

also @bralax make sure you are using latest version.

bralax commented 3 years ago

I was on one release prior (3.13.5) and updated to 3.13.6 which did not resolve the issue.

I eventually added a primary key (I was just testing things out so I had not marked a column as a primary key) and in doing so it now is giving correct results. I know that this fixed it in part because I made a second table and without a primary key, that table is having the same issue as the original table. Is there a requirement that every table has a primary key? I see that it is highly recommended in the documentation but it does not say that it is mandatory.

ujjwalguptaofficial commented 3 years ago

yes it is actually mandatory to have primary key. I will replace "highly recommended" by "mandatory" in the doc.

ujjwalguptaofficial commented 3 years ago

I think , there should be check for primary key when initiating table.