ujjwalguptaofficial / JsStore

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

strange behavior when using operator "!=" #366

Closed chrystalingus closed 2 months ago

chrystalingus commented 2 months ago

Hi there, I'm experiencing two strange behaviors (so far) and I can't make heads or tails of it.

Here's the executing code: image It is pretty straight forward and I included all the relevant debug console.logs.

When I use the "!=" operator, I get one result where there should be many: image

As soon as I change it to "<", I get all the expected results: image

There's a similar behavior when I try to write an "or" construct: expected: 14 results image

In both cases ("!=" operator and "or" construct), I get only one result. What am I doing wrong?

Best regards chrystalingus

ujjwalguptaofficial commented 2 months ago

I am not able to reproduce this. I tried this - https://ujjwalguptaofficial.github.io/idbstudio/?db=Demo&query=select(%7B%0A%20%20%20%20from%3A%20%22Products%22%2C%0A%20%20%20%20where%3A%20%7B%0A%20%20%20%20%20%20%20%20price%3A%7B%0A%20%20%20%20%20%20%20%20%20%22!%3D%22%3A20%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%7D)%3B%0A

Could you please try to reproduce here ? or provide me something where i can see the issue.

chrystalingus commented 2 months ago

Thank you for your reply. I will try to reproduce it there on Monday. Until then, have a great weekend!

chrystalingus commented 2 months ago

Hi @ujjwalguptaofficial , as my problem occurred in an elaborate environment, I decided to try and recreate it separately: https://dev.virtual-tool.de/test_independent.php where there is nothing else going on server-side or client-side and I hard-coded all table definitions and content.

And I turned up with exactly the same behavior. :( Please have a look at the console (I work in Chrome but also verified the result in Firefox) and the page source code. It should be very straightforward.

Do you have any insight here?

Best regards chrystalingus

ujjwalguptaofficial commented 2 months ago

This is because of no primary key found in the table shipping, due to no primary key it's not able to distinguish between the data and that's why one result.

Please add the primary key and it should work. Here is doc for primary key - https://jsstore.net/docs/database/column#options

chrystalingus commented 2 months ago

You're a lifesaver! Thank you! I never would have figured this out. I was pulling my data from a MySQL view instead of a table, which is why there was no primary key to begin with.

Maybe consider a console warning when no primary key is defined?

Anyway, thank you again! Hopefully, this helps out someone else too.

ujjwalguptaofficial commented 2 months ago

Yes, i am going to add warning.