typicaljoe / taffydb

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

not condition with in operator? #141

Open natarajgandhi opened 7 years ago

natarajgandhi commented 7 years ago

Hi,

I am trying to write a query to filter for array of values which do not belong to a column. Basically, trying to write a "not in" a set of values condition.

Kindly advise if I can achieve the same with Taffy. Went through the documentation in http://taffydb.com/writing_queries.html, however, couldn't locate a not in condition. Kindly advise.

Thanks and Regards, Nataraj

shawnsBrain commented 5 years ago

DB({column:{"!is":["val1","val2","val3"]}})

chrisregnier commented 4 years ago

There seems to be a bug here.

let DB = taffy( [ { myCol : 'val1' } ] );
assert(DB().count(), 1);   // only 1 record
assert(DB( { myCol: { 'is': [ 'val1', 'val2' ] } }).count(), 1);   //  myCol IN ['val1', 'val2']  as expected
assert(DB( { myCol: { 'is': [ 'val2', 'val1' ] } }).count(), 1);   //  reverse order and myCol IN ['val2', 'val1']  as expected
assert(DB( { myCol: { 'is': [ 'val3', 'val2' ] } }).count(), 0);   // myCol IN ['val3', 'val2']  is false as expected
assert(DB( { myCol: { '!is': ['val1', 'val2'] } }).count(), 0);   //  myCol NOT IN  ['val1', 'val2']  seems to return nothing as expected

assert(DB( { myCol: { '!is': ['val2', 'val1'] } }).count(), 0);   // fail, it returns the record.