Skip to content
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);

AND ( one property )

Select where name = "John";

people.select().where('name', 'John').get();

You can also pass in an object

people.select().where({'name': 'John'}).get();

AND ( multiple properties )

Select where name = "John" and city = "Atlanta"

people.select().where({'name': 'John', 'city': 'Atlanta'}).get();

OR

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();

AND/OR

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();

Notes

  • 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.

Clone this wiki locally