Or operations

Typically a query by example consists of AND operations. 

handler.query ({age:5, height:0.7});

Using constraints just gives us the opportunity for more complicated AND operations

var c = enums.CONSTRAINTS;
handler.query ( age: handler.constraints([[c.LTE,.9],[c.GTE,.5]]), age: handler.constraint([c.LT,7]));

Sometimes you want to to OR operations - for example people under 10 or over 25. Not all underlying databases even have an OR capability (for example DataStore), but database abstraction provides a consistent way to do OR operations across all supported back ends.

How to do ORS

The following syntax applies to all backends

Lets say you want to do these 2 queries and combine the results

handler.query ({color:'red'});
handler.query ({size:'big'});

Just make an array of queries

handler.query ([{size:'big'},{color:'red'}]);

You can mix in constraints as well if you want

var c = enums.CONSTRAINTS;
handler.query ([ {"location.country":"usa", "location.state":handler.constraints([c.IN,["il","ny"]])}, {"location.country":"uk", "location.city":"london"} ]);



Duplicates are automatically removed (if records qualify for more than one query they are returned only once)

For help and more information join our forum,follow the blog or follow me on twitter .

Comments