typicaljoe / taffydb

TaffyDB - an open source JavaScript Database for your browser
http://taffydb.com
MIT License
2.21k stars 285 forks source link

Complex queries -- Specific syntax needed for 'AND' #161

Open sharan-nyn opened 5 years ago

sharan-nyn commented 5 years ago

Hi, I am converting SQL WHERE clause to TaffyDB queries. I think I have found one possible combination that cannot be implemented into a TaffyDB query.

A query like:

(Type='Food' OR Amount=27) AND (Currency='INR' OR Amount=26)

can be converted to TaffyDB query as:

[
  [{"Type":{"==":"Food"}}, {"Amount":{"==":27}}],
  [{"Currency":{"==":"INR"}, {"Amount":{"==":26}}]
]

the [...] is used to group two filters in an 'OR' condition and 'comma' separation works like 'AND' in this case.

However query like:

(Type='Food' AND Amount=27) OR (Currency='INR' AND Amount=26)

Cannot be converted to TaffyDB query, since there is no specific syntax for 'AND' like 'OR' in TaffyDB.

mmikowski commented 4 years ago

Agreed. I believe one could write a callback function to sort, but this would be useful in the core.