Class: Query

Query

A class that defines a query on Built.io Backend

new Query(conditions){Query}

query.js, line 18
Constructs a query with initial query conditions
Name Type Description
conditions object Plain JavaScript object specifying conditions
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend
var query = Built.App('blt5d4sample2633b').Class('project').Query();
query
.where('username','John')
.exec()
.then(function(objects){
   // objects having username field with value 'John'
});

Methods

addQueryParams(key, value){Query}

query.js, line 381
Custom query parameter can be sent
Name Type Description
key String Query parameter name.
value String Query parameter value.
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
var query = query.addQueryParams('Custom_Query_Parameter','Custom_Value');
query.exec()
.then(function(objects){
   // Objects that pass the query condtion
});

and(queryArray){Query}

query.js, line 827
Combines all the queries together using AND operator
Name Type Description
queryArray Array Array of query objects
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backed
var app = Built.App('blt5d4sample2633b');
var query = app.Class('project').Query();
var query1 = query.where('name','Super Project #41!');
var query2 = query.where('description','Small description');
var queryArray = [query1,query2];
var andQuery = query.and(queryArray);

ascending(uid){Query}

query.js, line 777
Gets the objects in ascending order
Name Type Description
uid String Uid of the field based on which the ordering should be done
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query returns a 'Query' constructor
// 'project' is a uid of a class on Built.io Backed
var app = Built.App('blt5d4sample2633b');
var Query = app.Class('project').Query;
var query = Query();
query = query.ascending('name'); 

containedIn(uid, array){Query}

query.js, line 706
Gets the objects that have its field value matching the contents of array
Name Type Description
uid String The field's uid
array Array The array against which the field value will be compared
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query returns a 'Query' constructor
// 'project' is a uid of a class on Built.io Backed
var app = Built.App('blt5d4sample2633b');
var Query = app.Class('project').Query;
var query = Query();
query = query.containedIn('severity',["Show Stopper","Critical"])
query.exec()
.then(function(query){
   // Fetches all objects that have severity as "Show Stopper" or "Critical"
});

count(){Query}

query.js, line 422
Gets only the count of the number of objects that pass the query condition
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
query = query.count();
query.exec()
.then(function(count){
   // count of the number of objects fetched
})  

delete(){Promise.<null>}

query.js, line 1524
Deletes all the objects that fulfill the query condition
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backed
var Query = Built.App('blt5d4sample2633b').Class('project').Query;
var query = Query();
query = query.containedIn('uid',['blt51dsampl79eaa8d7','bltbcfdetest2772f9d']);
query.delete()
.then(function(data){
   console.log(data) // null;
});

deltaAll(date){Query}

query.js, line 1118
Get the objects which were created, updated or deleted on or after the given date
Name Type Description
date Date | String Instance of Date or a string in the following format 'YYYY-MM-DD'
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backed

var query = Built.App('blt5d4sample2633b').Class('project').Query();
//Example demonstrate method accepting a formated string as date. 
var query = query.deltaAll('2014-09-02');
query.exec()
.then(function(object)({
   // object.created   //is a array of all object that were created on or after the given date.    
   // object.updated   //is a array of all object that were update on or after the given date.  
   // object.deleted   //is a array of all object that were deleted on or after the given date.  
}));
//Example demonstrate method accepting a date instance.
var query = Built.App('blt5d4sample2633b').Class('project').Query();
var query = query.deltaAll(new Date());     

deltaCreatedFrom(date){Query}

query.js, line 1019
Gets the objects that were created on or after the given date
Name Type Description
date Date | String Instance of Date or a string in the following format 'YYYY-MM-DD'
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backed

//Example demonstrate method accepting a formated string as date. 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
var query = query.deltaCreatedFrom('2014-09-02');
query.exec()
.then(function(object)({
   // object.created is array of all objects that 
   // were created on or after the given date
}));

//Example demonstrate method accepting a date instance.
var query = Built.App('blt5d4sample2633b').Class('project').Query();
var query = query.deltaCreatedFrom(new Date());    
query.exec()
.then(function(object)({
   // object.created is array of all objects that 
   // were created on or after the given date
}));

deltaDeletedFrom(date){Query}

query.js, line 1085
Gets the objects which were deleted on or after the given date
Name Type Description
date Date | String Instance of Date or a string in the following format 'YYYY-MM-DD'
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backed

//Example demonstrate method accepting a formated string as date. 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
var query = query.deltaDeletedFrom('2014-09-02');
query.exec()
.then(function(object)({
   // object.deleted is array of all objects that were deleted on or 
   // after the given date
}));

//Example demonstrate method accepting a date instance.
var query = Built.App('blt5d4sample2633b').Class('project').Query();
var query = query.deltaDeletedFrom(new Date());
query.exec()
.then(function(object)({
   // object.deleted is array of all objects that were deleted on or 
   // after the given date
}));     

deltaUpdatedFrom(date){Query}

query.js, line 1052
Gets the objects that were updated on or after the given date
Name Type Description
date Date | String Instance of date or a string in the following format 'YYYY-MM-DD'.
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backed

//Example demonstrate method accepting a formated string as date. 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
var query = query.deltaUpdatedFrom('2014-09-02');
query.exec()
.then(function(object)({
   // object.updated is array of all objects that were updated on
   //or after the given date
}));

//Example demonstrate method accepting a date instance.
var query = Built.App('blt5d4sample2633b').Class('project').Query();
var query = query.deltaUpdatedFrom(new Date());
query.exec()
.then(function(object)({
   // object.updated is array of all objects that were updated on 
   //or after the given date
}));    

descending(uid){Query}

query.js, line 795
Gets the objects in descending order
Name Type Description
uid String Uid of the field based on which the ordering should be done
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query returns a 'Query' constructor
// 'project' is a uid of a class on Built.io Backed
var app = Built.App('blt5d4sample2633b');
var Query = app.Class('project').Query;
var query = Query();
query = query.descending('name'); 

doesNotExists(field_uid){Query}

query.js, line 245
Gets all the object in which a value does not exists for a given field. i.e. Any object which has a value other than 'undefined' for that field is rejected.
Name Type Description
field_uid String The field whose value is to be checked
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend
var query = Built.App('blt5d4sample2633b').Class('project').Query();
// Fetches all the objects that don't have a value for "name" field
query = query.doesNotExists('name');
query.exec()
.then(function(objects){
});

dontSelect(primaryKey, query, foriegnKey){Query}

query.js, line 312
Fires a select query on another class and gets objects that do not pass the query conditions. Similar to 'Joins' in relational databases like SQL.
Name Type Description
primaryKey String Field in base class which should be used in join.
query Query Query to be fired on the referred class.
foriegnKey String Field in referred class which should be used in join.
Example
// Example statement: Consider a class Person which has a reference field 'location', which refers to 'Address' class.
// You should execute the below given query to retrieve all persons who do not live in 'Mumbai';

// First lets create a query which retrieves all objects of 'Address' class having 'city' as 'Mumbai'.
	
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend
var queryOnAddressCls = Built.App('blt5d4sample2633b').Class('address').Query()
	                 .where('city', 'Mumbai');

// Now we can create a select query for retriving all persons from 'Person' class whoses location is not 'Mumbai'.

var query = Built.App('blt5d4sample2633b').Class('project').Query();
//'location' field contains uid of the address object whose city field anything other than Mumbai.
.dontSelect('location', queryOnAddressCls, 'uid')  
.exec()
.then(function(objects){
   // Fetches all person who don't live in Mumbai.
});

except(fieldUidArray){Query}

query.js, line 1562
Removes a set of fields from response
Name Type Description
fieldUidArray Array Array of field uid's that need to be excluded from response
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backed
var Query = Built.App('blt5d4sample2633b').Class('project').Query;
var query = Query();
query = query.where('uid','blt111sample24a6b');
query = query.except(['username']);
query.exec()
.then(function(res){
   // The response won't contain username field
});

exceptReference(Reference, fieldUidArray){Query}

query.js, line 1585
Removes a set of fields from the referenced object
Name Type Description
Reference String field uid
fieldUidArray Array Array of field uids that need to be excluded from the referenced object
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query returns a 'Query' constructor
// 'project' is a uid of a class on Built.io Backed

var Query = Built.App('blt5d4sample2633b').Class('project').Query;
var query = Query();
query = query.where('uid','blt111sample24a6b');
query = query.include(['per_city'])
query = query.exceptReference('per_city',['city']); //per_city is a reference field that references the Address class
query.exec()
.then(function(res){
   // The response won't contain city field in the Address object
});

exec(){Promise.<Variable>}

query.js, line 1216
Executes the query
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backed

var app = Built.App('blt5d4sample2633b');
var query = app.Class('project').Query({
   name:'John'
});
//Normal Query
query.exec()
.then(function(objects)({
   // Fetches all objects having name John
}));

//Query containing query.includeCount() 
query
.includeCount()
.exec()
.spread(function(objects,count)({
   //"objects" is array of objects return.
   //"count" is the number of objects returned.
}));
//Query containing query.includeCount() and query.includeSchema() 
query
.includeCount()
.includeSchema()
.exec()
.spread(function(objects,schema,count)({
   //"objects" is array of objects returned.
   //"count" is the number of objects returned.
}));        
//Query containing query.count()
query
.count();
.exec()
.then(function(count)({
   //Count is the number of objects returned.
}));

//When a query consists of a delta parameter, the response is plain javascript object with keys for each delta
var app   = Built.App('blt5d4sample2633b');
var query = app.Class('project').Query({
   name:'John'
});
query.deltaCreatedFrom(new Date())
.exec()
.then(function(result)({
   // result.created is array of all objects that were created on or 
   // after the given date
}));

//When an query is following Built.CachePolicy.CACHE_THEN_NETWORK the ouput structure is as follows
query.setCachePolicy(Built.CachePolicy.CACHE_THEN_NETWORK);
var result = query.exec(); // This is the only use case where exec returns an object and not a promise.

//object.cache is a promise that is resloved when data is avaliable through cache. 
result.cache.then(function(objects){   
   // objects is array of SDK objects
});

//object.network is a promise that is resloved when data is avaliable through network. 
result.network.then(function(objects){ 
   // objects is array of SDK objects
});
		
// object.both is a function that accepts a callback which is executed twice, 
// once when the data is avaliable through cache and then again when its avaliable through network.
result.both(function(error,data){ 
   // error is the network error.   
});

exists(field_uid){Query}

query.js, line 222
Gets all the object in which a value exists for a given field. i.e. Any object which has a value of 'undefined' for that field is filtered.
Name Type Description
field_uid String The field whose value is to be checked
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend
var query = Built.App('blt5d4sample2633b').Class('project').Query();
// Fetches all the objects that have have a value for "name" field
query
.exists('name');
.exec()
.then(function(objects){
   console.log(objects[0].toJSON())
});

exportToExcel(){Promise}

query.js, line 1693
Export objects from a class to an Excel File
Example
// 'blt5d4sample2633b' is a dummy Application API key

On Browser

var query = Built.App("blt5d4sample2633b").Class('sample').Query(); query.exportToExcel();

On Node

var query = Built.App("blt5d4sample2633b").Class('sample').Query(); query.exportToExcel() .then(function(res) { // a nodejs 'Stream' is returned });

getBlacklist(){Array}

query.js, line 1392
Get the array of all the Blacklisted fields
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backed

//Example demonstrate method accepting a updated_at field. 
var query = Built.App('blt5d4sample2633b')
             .setCachePolicy(Built.CachePolicy.CACHE_ELSE_NETWORK)
             .Class('project').Query();
var query = query
             .lessThan('updated_at', new Date())
             .setBlacklist(['updated_at']);

var blacklist = query.getBlacklist()

getHeaders(){object}

query.js, line 186
Gets the header object for this query
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend
var query = Built.App('blt5d4sample2633b').Class('project').Query();
var headers = query.getHeaders();

greaterThan(field_uid, value){Query}

query.js, line 877
Gets all the objects that have its field_uid's value greater than the given value
Name Type Description
field_uid String The uid of the field that needs to be compared
value Number A numeric value
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'milestone' is a uid of a class on Built.io Backed
var app = Built.App('blt5d4sample2633b');
var query = app.Class('milestone').Query();
query.greaterThan('end_date',new Date());

greaterThanOrEqualTo(field_uid, value){Query}

query.js, line 896
Gets all the objects that have its field_uid's value greater than or equal to the given value
Name Type Description
field_uid String The uid of the field that needs to be compared
value Number A numeric value
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'milestone' is a uid of a class on Built.io Backed
var app = Built.App('blt5d4sample2633b');
var query = app.Class('milestone').Query();
query.greaterThanOrEqualTo('end_date',new Date());

include(field_Uids){Query}

query.js, line 442
By default, when a object is fetched referenced object's uids are returned in response. Using this method you can retrieve the reference object itself.
Name Type Description
field_Uids Array Array of reference field uids whose actual referenced object is to be included
Example
// Consider a Bugs class has a reference field "project" which is referring to Project class.
// This function would include all objects that are referred by "project" field

// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'bugs' is a uid of a class on Built.io Backend 
var query = Built.App('blt5d4sample2633b').Class('bugs').Query();
query = query.include(['project']);

includeCount(){Query}

query.js, line 407
Includes the count of the number of objects returned along with the actual objects in response
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
query = query.includeCount();

includeDrafts(){Query}

query.js, line 528
Includes all unpublished objects of a class
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
query = query.includeDrafts();

includeOwner(){Query}

query.js, line 496
Includes owner information for each object in the response
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
query = query.includeOwner();       

includeSchema(){Query}

query.js, line 512
Include the schema in response
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
query = query.includeSchema();       

inQuery(field_uid, queryObj){Query}

query.js, line 575
Applies query on the referenced class' objects and fetches all objects from the referring(base) class which referred to these filtered out referenced objects
Name Type Description
field_uid String The uid of reference field
queryObj Query The query that should be applied on the referenced class' objects
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query returns a 'Query' constructor
// 'project' is a uid of a class on Built.io Backend 
// 'bugs' is a uid of a class on Built.io Backed

// Consider class Bugs has a reference field 'project' which refers the Project class

var app = Built.App('blt5d4sample2633b');
var query = app.Class('bugs').Query();

// Query which would be applied on Project class
var whereQuery = query.where('name','Super Project #41!');          

var inQuery = query.inQuery('project', whereQuery);  
inQuery
.exec()
.then(function(res){
   //Returns all objects from Bugs class whose 'project' field references to Project class objects that have name as 'Super Project #41!'
});

lessThan(field_uid, value){Query}

query.js, line 915
Gets all the objects that have its field_uid's value less than the given value
Name Type Description
field_uid String The uid of the field that needs to be compared
value Number A numeric value
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'milestone' is a uid of a class on Built.io Backed
var app = Built.App('blt5d4sample2633b');
var query = app.Class('milestone').Query();
query.lessThan('end_date',new Date());

lessThanOrEqualTo(field_uid, value){Query}

query.js, line 934
Gets all the objects that have its field_uid's value less than or equal to the given value
Name Type Description
field_uid String The uid of the field that needs to be compared
value Number A numeric value
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'milestone' is a uid of a class on Built.io Backed
var app = Built.App('blt5d4sample2633b');
var query = app.Class('milestone').Query();
query.lessThanOrEqualTo('end_date',new Date());

limit(number){Query}

query.js, line 478
Limits the response to contain only 'n' number of objects
Name Type Description
number Number The number of objects to be limited
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
// Would return only five objects even if more than five objects pass the condition
query = query.limit(5);       

matches(field_uid, regex, options){Query}

query.js, line 634
Gets all the objects that match the regular expression
Name Type Description
field_uid String The field on which the regular expression is applied
regex String The regular expression
options String Options for regular expression (Optional Defaults to 'i')
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backed

var app = Built.App('blt5d4sample2633b');
var query = app.Class('project').Query();
// Fetches all objects whose name start with 'abc'
query = query.matches('name','^abc'); 

nearLocation(location, radius){Query}

query.js, line 1482
Fetches objects that are nearer to a specified location within the given radius
Name Type Description
location Location | String Built.Location object or Object's uid in the latter case, location of the object is being used
radius Number The radius within which to query (Optional & Defaults to 1000)
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backed
var point = Built.Location(60,80);
var Query = Built.App('blt5d4sample2633b').Class('project').Query;
var query = Query();
query = query.nearLocation(point,1200);

notContainedIn(uid, array){Query}

query.js, line 742
Gets the objects that don't have its field value matching the contents of array
Name Type Description
uid String The field's uid
array Array The array against which the field value will be compared
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query returns a 'Query' constructor
// 'project' is a uid of a class on Built.io Backed@example
var app = Built.App('blt5d4sample2633b');
var Query = app.Class('project').Query;
var query = Query();
query  = query.notContainedIn('severity',["Show Stopper","Critical"])
query.exec()
.then(function(query){
   // Fetches all objects which don't have severity as "Show Stopper" or "Critical"
});

notEqualTo(field_uid, value){Query}

query.js, line 953
Gets all the object that have its field_uid's value not equal to the given value
Name Type Description
field_uid String The uid of the field that needs to be compared
value Number A numeric value
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'milestone' is a uid of a class on Built.io Backed
var app = Built.App('blt5d4sample2633b');
var query = app.Class('milestone').Query();
query.notEqualTo('end_date',new Date());

notInQuery(field_uid, queryObj){Query}

query.js, line 607
Applies query conditions on referenced class' objects and fetches all objects from the referring class that did not refer to these objects
Name Type Description
field_uid String The uid of reference field
queryObj Query Query object containing the query
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query returns a 'Query' constructor
// 'bugs' is a uid of a class on Built.io Backed
// Consider class Bugs has a reference field 'project' which refers the Project class
  
var app = Built.App('blt5d4sample2633b');
var query = app.Class('project').Query();           

// Query which would be applied on Project class
var whereQuery = query.where('name','Super Project #41!');          

var inQuery = query.notInQuery('project',whereQuery);  
inQuery.exec().then(function(res){
   //Returns all objects from Bugs class whose 'project' field references to Project class objects that don't have name as 'Super Project #41!'
});

only(field_Uids){Query}

query.js, line 1611
This method should be used when it is required to only have a set of fields in the base class object's respone
Name Type Description
field_Uids Array Array of field uid's that need to be present in the response
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query returns a 'Query' constructor
// 'project' is a uid of a class on Built.io Backed
var Query = Built.App('blt5d4sample2633b').Class('project').Query;
var query = Query();
query = query.where('uid','blt111sample24a6b');
query = query.only(['username']);
query.exec()
.then(function(res){
   // The response will only have the username field
});

onlyDrafts(){Query}

query.js, line 544
Includes only unpublished objects of a class
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
query = query.onlyDrafts();

onlyReference(Reference, field_Uids){Query}

query.js, line 1634
This method should be used when it is required to only have a set of fields in the referenced object
Name Type Description
Reference String field uid
field_Uids Array Array of field uids that need to be present in the referenced object
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query returns a 'Query' constructor
// 'bugs' is a uid of a class on Built.io Backed

var Query = Built.App('blt5d4sample2633b').Class('bugs').Query;
var query = Query();
query = query.where('uid','blt111sample24a6b');
query = query.include(['project']);
// 'name' is a reference field that references the Project class
query = query.onlyReference('project',['name']); 

query.exec()
.then(function(res){
   // The response will only have name field in the Project object
});

or(queryArray){Query}

query.js, line 848
Combines all the queries together using OR operator
Name Type Description
queryArray Array Array of Query objects containing conditions
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backed
var app = Built.App('blt5d4sample2633b');
var query = app.Class('project').Query();
var query1 = query.where('name','Super Project #41!');
var query2 = query.where('description','Small description');
var queryArray = [query1,query2];
var orQuery = query.or(queryArray);

removeHeader(header){Query}

query.js, line 132
Removes a header from a query
Name Type Description
header String The header that needs to be removed
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
query = query.removeHeader('My-Custom-Header');

removeMasterKey(){Query}

query.js, line 170
Removes the master key from Query
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend
var query = Built.App('blt5d4sample2633b').Class('project').Query();
query = query.removeMasterKey(); 

select(primaryKey, query, foriegnKey){Query}

query.js, line 278
Fires a select query on another class and gets objects that pass the query conditions. Similar to 'Joins' in relational databases like SQL.
Name Type Description
primaryKey String Field in base class which should be used in join.
query Query Query to be fired on the referred class.
foriegnKey String Field in referred class which should be used in join.
Example
// Example statement: Consider a class Person which has a reference field 'location', which refers to 'Address' class.
// You should execute the below given query to retrieve all persons who live in 'Mumbai';
  
//First lets create a query which retrieves all objects of 'Address' class having 'city' as 'Mumbai'.
	
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend
var queryOnAddressCls = Built.App('blt5d4sample2633b').Class('address').Query()
    .where('city', 'Mumbai');
 
// Now we can create a select query for retriving all persons from 'Person' class whoses location is 'Mumbai'.

var query = Built.App('blt5d4sample2633b').Class('project').Query();
// 'location' field contains uid of the address object whose city field is Mumbai
.select('location', queryOnAddressCls, 'uid')  
.exec()
.then(function(objects){
   // Fetches all person who live in Mumbai.
});

setBlacklist(fieldUidArray){Query}

query.js, line 1350
Whenever you execute a query that contains some dynamic field, it generates a new hashkey everytime. Using this method, you can restrict the query from creating a new hashkey whenever it is executed. It blacklists the given fields, and returns the same hashkey everytime.
Name Type Description
fieldUidArray Array Array of field uid's which are to be blacklisted
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backed

//Example demonstrate method accepting a updated_at field. 
var query = Built.App('blt5d4sample2633b')
             .setCachePolicy(Built.CachePolicy.CACHE_ELSE_NETWORK)
             .Class('project').Query();
var query = query
             .lessThan('updated_at', new Date())
             .setBlacklist(['updated_at']);
var result = project.exec(); 

result.cache.then(function(objects){   
   // objects from cache
});

result.network.then(function(objects){ 
   // objects from network
});

setCachePolicy(value){Query}

query.js, line 972
Sets the a cache policy for this query
Name Type Description
value Number A numeric value
Throws:
new Error("Invalid cache policy");
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backed
var query = Built.App('blt5d4sample2633b').Class('project').Query();
query = query.setCachePolicy(Built.CachePolicy.CACHE_ELSE_NETWORK);

setHeader(header, value){Query}

query.js, line 109
Set a header in query
Name Type Description
header String The header key
value String The header value
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
query = query.setHeader('My-Custom-Header','MyValue');

setMasterKey(masterKey){Query}

query.js, line 154
Sets the master key for a query
Name Type Description
masterKey String The master key value
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend
var query = Built.App('blt5d4sample2633b').Class('project').Query();
query = query.setMasterKey('blt111sample24a6b');  

setRawQuery(Reference, field_Uids){Query}

query.js, line 1663
Adds a rawQuery
Name Type Description
Reference String field uid
field_Uids Array Array of field uids that need to be present in the referenced object
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query returns a 'Query' constructor
// 'bugs' is a uid of a class on Built.io Backed

var Query = Built.App('blt5d4sample2633b').Class('bugs').Query;
var query = Query();
query = query.setRawQuery({
   name: 'Super Project #41!'
})
query.exec()
.then(function(res){
   // The response will only have name field in the Project object
});

skip(number){Query}

query.js, line 462
Skip 'n' number of objects
Name Type Description
number Number The number of objects to be skipped
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
query = query.skip(5);

toBackbone(){Query}

query.js, line 85
Returns the result as a Backbone collection
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
query
.toBackbone()
.exec()
.then(function(res){
   console.log(res); // Backbone collection
});

toJSON(){Query}

query.js, line 59
Returns the result as an array of plain JavaScript objects
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
query
.toJSON()
.exec()
.then(function(objects){
   // array of plain javascript objects
   console.log(objects); 
});

where(key, value){Query}

query.js, line 346
Gets the objects that match the where condition
Name Type Description
key String The key
value String The value
Example
// 'blt5d4sample2633b' is a dummy Application API key
// 'Class('class_name').Query() returns a 'Query' instance
// 'project' is a uid of a class on Built.io Backend 
var query = Built.App('blt5d4sample2633b').Class('project').Query();
query  = query.where('name','Super Project #41!');
query
.exec()
.then(function(objects){
  //fetches all the objects whose name is 'Super Project #41!' 
});