new Query(options)
creates a Query object that can be used in Collection methods or on its own to operate on items on the server
Parameters:
| Name | Type | Description |
|---|---|---|
options |
Object | Object that has configuration values used when instantiating a Query object |
- Source:
Methods
-
equalTo(field, value)
-
Creates an equality clause in the query object
Parameters:
Name Type Description fieldString String defining what attribute to compare valueString String or Number that is used to compare against - Source:
Example
Adding an equality clause to a query
var query = new ClearBlade.Query(); query.equalTo('name', 'John'); //will only match if an item has an attribute 'name' that is equal to 'John' -
fetch(callback)
-
Reqests an item or a set of items from the query. Requires that the Query object was initialized with a collection.
Parameters:
Name Type Description callbackfunction Supplies processing for what to do with the data that is returned from the collection - Source:
Examples
The typical callback
var callback = function (err, data) { if (err) { //error handling } else { console.log(data); } };Fetching data from a collection
var returnedData = []; var callback = function (err, data) { if (err) { throw new Error (data); } else { returnedData = data; } }; query.fetch(callback); //this will give returnedData the value of what ever was returned from the server. -
greaterThan(field, value)
-
Creates a greater than clause in the query object
Parameters:
Name Type Description fieldString String defining what attribute to compare valueString String or Number that is used to compare against - Source:
Example
Adding a greater than clause to a query
var query = new ClearBlade.Query(); query.greaterThan('age', 21); //will only match if an item has an attribute 'age' that is greater than 21 -
greaterThanEqualTo(field, value)
-
Creates a greater than or equality clause in the query object
Parameters:
Name Type Description fieldString String defining what attribute to compare valueString String or Number that is used to compare against - Source:
Example
Adding a greater than or equality clause to a query
var query = new ClearBlade.Query(); query.greaterThanEqualTo('age', 21); //will only match if an item has an attribute 'age' that is greater than or equal to 21 -
lessThan(field, value)
-
Creates a less than clause in the query object
Parameters:
Name Type Description fieldString String defining what attribute to compare valueString String or Number that is used to compare against - Source:
Example
Adding a less than clause to a query
var query = new ClearBlade.Query(); query.lessThan('age', 50); //will only match if an item has an attribute 'age' that is less than 50 -
lessThanEqualTo(field, value)
-
Creates a less than or equality clause in the query object
Parameters:
Name Type Description fieldString String defining what attribute to compare valueString String or Number that is used to compare against - Source:
Example
Adding a less than or equality clause to a query
var query = new ClearBlade.Query(); query.lessThanEqualTo('age', 50); //will only match if an item has an attribute 'age' that is less than or equal to 50 -
notEqualTo(field, value)
-
Creates a not equal clause in the query object
Parameters:
Name Type Description fieldString String defining what attribute to compare valueString String or Number that is used to compare against - Source:
Example
Adding a not equal clause to a query
var query = new ClearBlade.Query(); query.notEqualTo('name', 'Jim'); //will only match if an item has an attribute 'name' that is not equal to 'Jim' -
or(that)
-
chains an existing query object to the Query object in an or
Parameters:
Name Type Description thatQuery Query object that will be added in disjunction to this query object - Source:
Example
Chaining two queries together in an or
var query1 = new ClearBlade.Query(); var query2 = new ClearBlade.Query(); query1.equalTo('name', 'John'); query2.equalTo('name', 'Jim'); query1.or(query2); //will match if an item has an attribute 'name' that is equal to 'John' or 'Jim' -
remove(callback)
-
Removes an item or set of items from the Query
Parameters:
Name Type Description callbackfunction Function that handles the response from the server - Source:
Example
Removing an item in a collection
//This example assumes that you have a collection with the item whose 'name' attribute is 'John' var query = new ClearBlade.Query({'collection': 'COLLECTIONID'}); query.equalTo('name', 'John'); var callback = function (err, data) { if (err) { throw new Error (data); } else { console.log(data); } }; query.remove(callback); //removes every item whose 'name' attribute is equal to 'John' -
update(changes, callback)
-
Updates an existing item or set of items. Requires that a collection was set when the Query was initialized.
Parameters:
Name Type Description changesObject Object representing the attributes that you want changed callbackfunction Function that handles the response of the server - Source:
Example
Updating a set of items
//This example assumes a collection of items that have the columns name and age. var query = new ClearBlade.Query({'collection': 'COLLECTIONID'}); query.equalTo('name', 'John'); var changes = { age: 23 }; var callback = function (err, data) { if (err) { throw new Error (data); } else { console.log(data); } }; query.update(changes, callback); //sets John's age to 23