typicaljoe / taffydb

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

how to use "!is" by array ? #124

Open Iamlars opened 8 years ago

Iamlars commented 8 years ago

I want to filter data use !is like '{city:{"!is": ["a","b","c"]}}',but it is not work well.

IvanBrkicNeuralab commented 7 years ago

I had a similar issue:

product=[
  {
    "attributes":{"attribute_pa_excitation_emission":"350-448","pa_size":"200-assays"}
  },
  {
    "attributes":{"attribute_pa_excitation_emission":"800-448","pa_size":"100-assays"}
  }
];
db = TAFFY();

product.forEach(function(el) {
  db.insert(el);
});

I can filter for "pa_size" but not for attribute_pa_excitation_emission

search = baza({'attributes':{"pa_size":"200-assays"}}).get(); //finds results
search = baza({'attributes':{"attribute_pa_excitation_emission":"800-448"}}).get(); // nothing

After 2 days i found out the rule: If the string contains "is" - no go. Any other string works good. Hope this helps someone.

TyeS2K commented 5 years ago

!is also fails with number arrays. You can play with this sample and toggle the "is" operator to see the failure.

`        var people= TAFFY();
        people.insert({"fname":"Bruce","lname":"Wayne", "age": 18});
        people.insert({"fname":"Peter","lname":"Parker", "age": 18});
        people.insert({"fname":"Clark","lname":"Kent", "age": 23});
        people.insert({"fname":"Tyrone","lname":"Lee", "age": 43});
        people.insert({"fname":"Linda","lname":"Lee", "age": 39});

        write("people({age: {'!is': [39, 18, 43]}}).get()");
        write("people().count()");
        write("people().first()");
        write("people().select('fname')");

        write("people.sort('fname desc');people().select('fname')");
         function write(func){
            var ret = eval(func);
            var output = (typeof ret === 'object') ? JSON.stringify(ret) : ret;
            document.getElementById('results').innerHTML+= '<li>' + func + '<br />=><b>'+output+'</b>';
        }