-
Notifications
You must be signed in to change notification settings - Fork 0
Where
Angel Alvarado edited this page Nov 21, 2015
·
1 revision
#Where
##.where();
The where method can accept a variety of arguments depending on the query you want to run against the collection. Below are the various forms.
// create new jsql object
var people = new JSQL(data);Select where name = "John";
people.select().where('name', 'John').get();You can also pass in an object
people.select().where({'name': 'John'}).get();Select where name = "John" and city = "Atlanta"
people.select().where({'name': 'John', 'city': 'Atlanta'}).get();To make OR queries pass in multiple objects to search for.
Select where name = "Chris" or name = "Mike"
people.select().where({'name': 'Chris'}, {'name': 'Mike'}).get();If you want to make complex AND/OR queries you can.
Find a person named Chris who lives in either Atlanta or Miami
people.select().where({'name': 'Chris', 'city': 'Atlanta'}, {'name': 'Chris', 'city': 'Miami'}).get();You could also create the arguments beforehand and pass it as a value.
var clause = [{'name': 'Chris', 'city': 'Atlanta'}, {'name': 'Chris', 'city': 'Miami'}];
people.select().where(clause).get();- Queries are case sensitive.
- All values are converted to strings before evaluating, reducing unpredictable results do to 'truthy' evaluation.
- Where clause only works with equality operations.