Filtering rules in JSON format
When is this useful?
If you want to use the same filtering rules for js Array.filter
and SQL where
.
Usage
var where = where//returns corresponding sql `where` clausewhere//returns compare function, usable for Array.filter
SQL where
where// returns `id` = 1 and name = 'Adam'where// returns `id` in (1, 2, 3)where// returns `id` >= 1 and `id` =< 2
Array.filter
var fruit = id: 1 name: 'Banana' id: 2 name: 'Apple' id: 3 name: 'Apple'fruit// fruit will be// [{id: 1, name: 'Banana'}]fruit// fruit will be// [{id: 1, name: 'Banana'}, {id: 2, name: 'Apple'}]fruit// fruit will be// [{id: 2, name: 'Apple'}, {id: 3, name: 'Apple'}]