Constructor
new DataObjectJunction(obj, association)
Parameters:
Name |
Type |
Description |
obj |
DataObject
|
An object which represents the parent data object |
association |
String
|
*
|
A string that represents the name of the field which holds association mapping or the association mapping itself. |
Properties:
Name |
Type |
Description |
baseModel |
DataModel
|
The model associated with this data object junction |
parent |
DataObject
|
Gets or sets the parent data object associated with this instance of DataObjectJunction class. |
mapping |
DataAssociationMapping
|
Gets or sets the mapping definition of this data object association. |
- Source:
Extends
Methods
Prepares an addition (e.g. ([field] + 4))
Parameters:
Name |
Type |
Description |
x |
number
|
*
|
The |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve a list of products
context.model('Product')
.select('id','name', 'price')
//perform ((ProductData.price + 100)>300)
.where('price').add(100).lowerThan(300)
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
all(callbackopt) → {Deferred|*}
Parameters:
Name |
Type |
Attributes |
Description |
callback |
function
|
<optional>
|
|
- Inherited From:
- Source:
Returns:
- If callback function is missing returns a promise.
-
Type
-
Deferred
|
*
Adds a field or an array of fields to select statement
Parameters:
Name |
Type |
Description |
attr |
String
|
Array
|
DataField
|
*
|
|
- Inherited From:
- Deprecated:
- Source:
Returns:
-
Type
-
DataQueryable
Prepares a logical AND expression
Parameters:
Name |
Type |
Description |
attr |
string
|
The name of field that is going to be used in this expression |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
context.model('Order').where('customer').equal(298)
.and('orderStatus').equal(1)
.list().then(function(result) {
//SQL: WHERE ((OrderData.customer=298) AND (OrderData.orderStatus=1)
done(null, result);
}).catch(function(err) {
done(err);
});
Parameters:
Name |
Type |
Attributes |
Description |
value |
Boolean
|
<optional>
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
average(attr, callbackopt) → {Deferred|*}
Executes the query against the current model and returns the average value of the given attribute.
Parameters:
Name |
Type |
Attributes |
Description |
attr |
string
|
|
A string that represents a field of the current model |
callback |
function
|
<optional>
|
A callback function where the first argument will contain the Error object if an error occured, or null otherwise. The second argument will contain the result, if any. |
- Inherited From:
- Source:
Returns:
- If callback parameter is missing then returns a Deferred object.
-
Type
-
Deferred
|
*
Example
//retrieve the average price of products sold during last month
context.model('Order')
.where('orderDate').greaterOrEqual(moment().startOf('month').toDate())
.average('orderedItem/price').then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
between(value1, value2) → {DataQueryable}
Prepares a comparison where the left operand is between two values
Parameters:
Name |
Type |
Description |
value1 |
*
|
The minimum value |
value2 |
*
|
The maximum value |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Examples
//retrieve products where price is between 150 and 250
context.model('Product')
.where('price').between(150,250)
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
//The result set of this example may be:
id name model price
--- ------------------------------------------ ------ ------
367 Asus Transformer Book T100 HD2895 224.52
380 Zotac Zbox Nano XS AD13 Plus WC5547 228.05
384 Apple iPad Air ZE6015 177.44
401 Intel Core i7-4960X Extreme Edition SM5853 194.61
440 Bose SoundLink Bluetooth Mobile Speaker II HS5288 155.27
Prepares a bitwise and comparison.
Parameters:
Name |
Type |
Attributes |
Description |
value |
*
|
|
The right operand of the express |
result |
Number
|
<optional>
|
The result of a bitwise and expression |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve a list of permissions for model Person and insert permission mask (2)
context.model('Permission')
//prepare bitwise AND (((PermissionData.mask & 2)=2)
.where('mask').bit(2)
.and('privilege').equal('Person')
.and('parentPrivilege').equal(null)
.list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
cache(valueopt) → {string|DataQueryable}
Gets or sets a boolean which indicates whether results should be cached or not. This parameter is valid for models which have caching mechanisms.
Parameters:
Name |
Type |
Attributes |
Description |
value |
string
|
<optional>
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
string
|
DataQueryable
Prepares a ceil mathematical expression
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
clear(callbackopt) → {Promise|*}
Removes all associations
Parameters:
Name |
Type |
Attributes |
Description |
callback |
function
|
<optional>
|
|
- Deprecated:
- This method is deprecated. Use DataObjectJunction.removeAll() instead.
- Source:
Returns:
-
Type
-
Promise
|
*
clone() → {DataQuerable|*}
Clones the current DataQueryable instance.
- Inherited From:
- Source:
Returns:
- The cloned object.
-
Type
-
DataQuerable
|
*
Prepares a string concatenation expression
Parameters:
Name |
Type |
Description |
s |
string
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Prepares a contains comparison (e.g. a string contains another string).
Parameters:
Name |
Type |
Description |
value |
*
|
The right operand of the expression |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Examples
//retrieve person where the given name contains
context.model('Person').select(['id','givenName','familyName'])
.where('givenName').contains('ex')
.list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
//The result set of this example may be:
id givenName familyName
--- --------- ----------
297 Alex Miles
353 Alexis Rees
count(callbackopt) → {Deferred|*}
Executes the query against the current model and returns the count of items found.
Parameters:
Name |
Type |
Attributes |
Description |
callback |
function
|
<optional>
|
A callback function where the first argument will contain the Error object if an error occured, or null otherwise. The second argument will contain the result, if any. |
- Inherited From:
- Source:
Returns:
- If callback parameter is missing then returns a Deferred object.
-
Type
-
Deferred
|
*
Example
//retrieve the number of a product's orders
context.model('Order')
.where('orderedItem').equal(302)
.count().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
countOf(name, aliasopt) → {*|QueryField}
Parameters:
Name |
Type |
Attributes |
Description |
name |
string
|
|
|
alias |
string
|
<optional>
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
*
|
QueryField
data(nameopt, valueopt) → {DataQueryable|*}
Gets or sets query data. This data may be used in before and after execute listeners.
Parameters:
Name |
Type |
Attributes |
Description |
name |
string
|
<optional>
|
|
value |
*
|
<optional>
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
|
*
Prepares a division (e.g. ([field] / 0.2))
Parameters:
Name |
Type |
Description |
x |
number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve a list of orders
context.model('Product')
.select('id','name', 'price')
//perform ((ProductData.price / 0.8)>500)
.where('price').divide(0.8).greaterThan(500)
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares an ends with comparison
Parameters:
Name |
Type |
Description |
obj |
*
|
The string to be searched for at the end of a field. |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Examples
//retrieve people whose given name ends with 'y'
context.model('Person')
.where('givenName').endsWith('y')
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
//Results
id givenName familyName
--- --------- ----------
257 Daisy Lambert
287 Zachary Field
295 Anthony Berry
339 Brittney Hunt
341 Kimberly Wheeler
Performs an equality comparison.
Parameters:
Name |
Type |
Description |
obj |
*
|
The right operand of the expression |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve a list of orders with order status equal to 1
context.model('Order').where('orderStatus').equal(1)
.list().then(function(result) {
//WHERE (OrderData.orderStatus=1)
done(null, result);
}).catch(function(err) {
done(err);
});
Sets an expandable field or collection of fields. An expandable field produces nested objects based on the association between two models.
Parameters:
Name |
Type |
Description |
attr |
string
|
*
|
A param array of strings which represents the field or the array of fields that are going to be expanded.
If attr is missing then all the previously defined expandable fields will be removed. |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Examples
//retrieve an order and expand customer field
context.model('Order')
//note: the field [orderedItem] is defined as expandable in model definition and it will produce a nested object for each order
.select('id','orderedItem','customer')
.expand('customer')
.where('id').equal(46)
.first().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
//Result:
{
"id": 46,
"orderedItem": {
"id": 413,
"additionalType": "Product",
"category": "Storage and Networking Gear",
"price": 647.13,
"model": "FY8135",
"releaseDate": "2015-01-15 18:07:42.000+02:00",
"name": "LaCie Blade Runner",
"dateCreated": "2015-11-23 14:53:04.927+02:00",
"dateModified": "2015-11-23 14:53:04.934+02:00"
},
"customer": {
"id": 317,
"additionalType": "Person",
"alternateName": null,
"description": "Nicole Armstrong",
"image": "https://s3.amazonaws.com/uifaces/faces/twitter/zidoway/128.jpg",
"dateCreated": "2015-11-23 14:52:57.886+02:00",
"dateModified": "2015-11-23 14:52:57.917+02:00"
}
}
//retrieve an order and do not expand customer field
{
"id": 46,
"orderedItem": {
"id": 413,
"additionalType": "Product",
"category": "Storage and Networking Gear",
"price": 647.13,
"model": "FY8135",
"releaseDate": "2015-01-15 18:07:42.000+02:00",
"name": "LaCie Blade Runner",
"dateCreated": "2015-11-23 14:53:04.927+02:00",
"dateModified": "2015-11-23 14:53:04.934+02:00"
},
"customer": 317
}
fieldOf(attr, aliasopt) → {DataQueryable|QueryField|*}
Parameters:
Name |
Type |
Attributes |
Description |
attr |
string
|
*
|
|
|
alias |
string
|
<optional>
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
|
QueryField
|
*
first(callbackopt) → {Deferred|*}
Executes the specified query against the underlying model and returns the first item.
Parameters:
Name |
Type |
Attributes |
Description |
callback |
function
|
<optional>
|
A callback function where the first argument will contain the Error object if an error occured, or null otherwise. The second argument will contain the result. |
- Inherited From:
- Source:
Returns:
-
Type
-
Deferred
|
*
Example
//retrieve an order by id
context.model('Order')
.where('id').equal(302)
.first().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Disables expandable fields
Parameters:
Name |
Type |
Attributes |
Description |
value |
boolean
|
<optional>
|
If the value is true the result will contain only flat objects -without any nested associated object-,
even if model definition contains expandable fields. If value is missing, the default parameter is true |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Examples
//retrieve a list of orders
context.model('Order')
.flatten()
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
//Results:
id customer orderStatus paymentMethod
-- -------- ----------- -------------
1 299 5 6
2 337 7 5
3 309 3 3
4 257 2 4
5 285 5 2
Prepares a floor mathematical expression
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
getBaseModel() → {DataModel}
Gets an instance of DataModel class which represents the data adapter of this association
- Source:
Returns:
-
Type
-
DataModel
Prepares an expression by getting the date only value of a datetime field
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve a list of orders
context.model('Order')
.select('id','paymentDue', 'orderDate')
.where('orderDate').getDate().equal('2015-01-16')
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares an expression by getting the day of the month of a datetime field
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve a list of orders
context.model('Order')
.where('orderDate').getYear().equal(2015)
.and('orderDate').getMonth().equal(1)
.and('orderDate').getDay().equal(16)
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares an expression by getting the year of a datetime field
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve a list of orders made during 2015
context.model('Order')
.where('orderDate').getYear().equal(2015)
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares an expression by getting the hours (from 0 to 23) a datetime field
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
getItem() → {Promise|*}
Executes the specified query against the underlying model and returns the first item.
- Inherited From:
- Source:
Returns:
-
Type
-
Promise
|
*
getItems() → {Promise|*}
- Inherited From:
- Source:
Returns:
-
Type
-
Promise
|
*
getLevels() → {number}
Gets the number of levels of the expandable objects
- Inherited From:
- Source:
Returns:
-
Type
-
number
Prepares an expression by getting the minutes (from 0 to 59) a datetime field
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Prepares an expression by getting the month (from 1 to 12) of a datetime field.
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve a list of orders made during October 2015
context.model('Order')
.where('orderDate').getYear().equal(2015)
.and('orderDate').getMonth().equal(10)
.take(5).list().then(function(result) {
console.table(result.records);
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares an expression by getting the seconds (from 0 to 59) a datetime field
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
getTypedItem() → {Promise|*}
Gets an instance of DataObject by executing the defined query.
- Inherited From:
- Source:
Returns:
-
Type
-
Promise
|
*
getTypedItems() → {Promise|*}
Gets a collection of DataObject instances by executing the defined query.
- Inherited From:
- Source:
Returns:
-
Type
-
Promise
|
*
getTypedList() → {Promise|*}
Gets a result set that contains a collection of DataObject instances by executing the defined query.
- Inherited From:
- Source:
Returns:
-
Type
-
Promise
|
*
Prepares an expression by getting the year of a datetime field
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve a list of orders made during 2015
context.model('Order')
.where('orderDate').getYear().equal(2015)
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares a greater than or equal comparison.
Parameters:
Name |
Type |
Description |
obj |
*
|
The right operand of the expression |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve a list of orders where product price is greater than or equal to 800
context.model('Order')
.where('orderedItem/price').greaterOrEqual(800)
.orderByDescending('orderDate')
.take(5)
.list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares a greater than comparison.
Parameters:
Name |
Type |
Description |
obj |
*
|
The right operand of the expression |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Examples
//retrieve a list of orders where product price is greater than 800
context.model('Order')
.where('orderedItem/price').greaterThan(800)
.orderByDescending('orderDate')
.select('id','orderedItem/name as productName', 'orderedItem/price as productPrice', 'orderDate')
.take(5)
.list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
//Results:
id productName productPrice orderDate
--- -------------------------------------------- ------------ -----------------------------
304 Apple iMac (27-Inch, 2013 Version) 1336.27 2015-11-27 23:49:17.000+02:00
322 Dell B1163w Mono Laser Multifunction Printer 842.86 2015-11-27 20:16:52.000+02:00
167 Razer Blade (2013) 1553.43 2015-11-27 04:17:08.000+02:00
336 Apple iMac (27-Inch, 2013 Version) 1336.27 2015-11-26 07:25:35.000+02:00
89 Nvidia GeForce GTX 650 Ti Boost 1625.49 2015-11-21 17:29:21.000+02:00
Prepares a group by expression
Parameters:
Name |
Type |
Attributes |
Description |
attr |
string
|
<repeatable>
|
A param array of string that represents the attributes which are going to be used in group by expression |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Examples
//retrieve products with highest sales during last month
context.model('Order')
.select('orderedItem/model as productModel', 'orderedItem/name as productName','count(id) as orderCount')
.where('orderDate').greaterOrEqual(moment().startOf('month').toDate())
.groupBy('orderedItem')
.orderByDescending('count(id)')
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
//Results
productModel productName orderCount
------------ --------------------------------------- ----------
SM5111 Brother MFC-J6920DW 3
FY8135 LaCie Blade Runner 3
HA6910 Apple iMac (27-Inch, 2013 Version) 2
LD4238 Dell XPS 18 2
HR6205 Samsung Galaxy Note 10.1 (2014 Edition) 2
Prepares a typical IN comparison.
Parameters:
Name |
Type |
Description |
objs |
Array
|
An array of values which represents the values to be used in expression |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve orders with order status 1 or 2
context.model('Order').where('orderStatus').in([1,2])
.list().then(function(result) {
//WHERE (OrderData.orderStatus IN (1, 2))
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares an indexOf comparison
Parameters:
Name |
Type |
Description |
s |
string
|
The string to search for |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Examples
//retrieve a list of persons
context.model('Person')
.select('givenName')
.where('givenName').indexOf('a').equal(1)
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
//Results:
givenName
---------
Daisy
Maxwell
Mackenzie
Zachary
Mason
insert(obj, callbackopt) → {Promise.<T>|*}
Inserts an association between parent object and the given object or array of objects.
Parameters:
Name |
Type |
Attributes |
Description |
obj |
*
|
Array
|
|
An object or an array of objects to be related with parent object |
callback |
function
|
<optional>
|
A callback function where the first argument will contain the Error object if an error occured, or null otherwise. |
- Source:
Returns:
- If callback parameter is missing then returns a Promise object.
-
Type
-
Promise.<T>
|
*
Example
//add a user (by name) in Administrators group
var groups = context.model('Group');
groups.where('name').equal('Administrators')
.first().then(function(result) {
var group = groups.convert(result);
group.property('members').insert({ name: 'alexis.rees@example.com' }).then(function() {
done();
});
}).catch(function(err) {
done(err);
});
Performs an equality comparison.
Parameters:
Name |
Type |
Description |
obj |
*
|
The right operand of the expression |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve a person with id equal to 299
context.model('Person').where('id').is(299)
.first().then(function(result) {
//WHERE (PersonData.id=299)
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares a string length expression
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Examples
//retrieve a list of persons
context.model('Person')
.select('givenName')
.where('givenName').length().equal(5)
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
//Results:
givenName
---------
Daisy
Peter
Kylie
Colin
Lydia
Sets the number of levels of the expandable attributes.
The default value is 1 which means that any expandable attribute will be flat (without any other nested attribute).
If the value is greater than 1 then the nested objects may contain other nested objects and so on.
Parameters:
Name |
Type |
Attributes |
Description |
value |
Number
|
<optional>
|
A number which represents the number of levels which are going to be used in expandable attributes. |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//get orders, expand customer and get customer's nested objects if any.
context.model('Order')
.orderByDescending('dateCreated)
.expand('customer')
.levels(2)
.getItems().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
list(callbackopt) → {Deferred|*}
Executes current query and returns a result set based on the specified paging parameters.
The result is an instance of DataResultSet. The returned records may contain nested objects
based on the definition of the current model (expandable fields).
This operation is one of the common data operations on MOST Data Applications
where the affected records may have nested objects which contain the associated objects of each object.
{
"total": 242,
"records": [
...
{
"id": 46,
"orderDate": "2014-12-31 13:35:41.000+02:00",
"orderedItem": {
"id": 413,
"additionalType": "Product",
"category": "Storage and Networking Gear",
"price": 647.13,
"model": "FY8135",
"releaseDate": "2015-01-15 18:07:42.000+02:00",
"name": "LaCie Blade Runner",
"dateCreated": "2015-11-23 14:53:04.927+02:00",
"dateModified": "2015-11-23 14:53:04.934+02:00"
},
"orderNumber": "DEF193",
"orderStatus": {
"id": 7,
"name": "Problem",
"alternateName": "OrderProblem",
"description": "Representing that there is a problem with the order."
},
"paymentDue": "2015-01-20 13:35:41.000+02:00",
"paymentMethod": {
"id": 7,
"name": "PayPal",
"alternateName": "PayPal",
"description": "Payment via the PayPal payment service."
},
"additionalType": "Order",
"description": null,
"dateCreated": "2015-11-23 21:00:18.306+02:00",
"dateModified": "2015-11-23 21:00:18.307+02:00"
}
...
]
}
Parameters:
Name |
Type |
Attributes |
Description |
callback |
function
|
<optional>
|
A callback function with arguments (err, result) where the first argument is the error, if any
and the second argument is an object that represents a result set |
- Inherited From:
- Source:
Returns:
- If callback is missing returns a promise.
-
Type
-
Deferred
|
*
Example
//retrieve products list order by price
context.model('Product')
.where('category').equal('LCDs and Peripherals')
.orderByDescending('price')
.take(3).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares a lower than or equal comparison.
Parameters:
Name |
Type |
Description |
obj |
*
|
The right operand of the expression |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve orders based on payment due date
context.model('Order')
.orderBy('paymentDue')
.where('paymentDue').lowerOrEqual(moment().subtract('days',-7).toDate())
.and('paymentDue').greaterThan(new Date())
.take(10).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares a lower than comparison
Parameters:
Name |
Type |
Description |
obj |
*
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
max(attr, callbackopt) → {Deferred|*}
Executes the query against the current model and returns the maximum value of the given attribute.
Parameters:
Name |
Type |
Attributes |
Description |
attr |
string
|
|
A string that represents a field of the current model |
callback |
function
|
<optional>
|
A callback function where the first argument will contain the Error object if an error occured, or null otherwise. The second argument will contain the result, if any. |
- Inherited From:
- Source:
Returns:
- If callback parameter is missing then returns a Deferred object.
-
Type
-
Deferred
|
*
Example
//retrieve the maximum price of products sold during last month
context.model('Order')
.where('orderDate').greaterOrEqual(moment().startOf('month').toDate())
.max('orderedItem/price').then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
migrate(callback)
Migrates the underlying data association adapter.
Parameters:
Name |
Type |
Description |
callback |
|
A callback function where the first argument will contain the Error object if an error occured, or null otherwise. |
- Overrides:
- Source:
migrate(callback)
Migrates current junction data storage
Parameters:
Name |
Type |
Description |
callback |
function
|
|
- Overrides:
- Source:
min(attr, callbackopt) → {Deferred|*}
Executes the query against the current model and returns the average value of the given attribute.
Parameters:
Name |
Type |
Attributes |
Description |
attr |
string
|
|
A string that represents a field of the current model |
callback |
function
|
<optional>
|
A callback function where the first argument will contain the Error object if an error occured, or null otherwise. The second argument will contain the result, if any. |
- Inherited From:
- Source:
Returns:
- If callback parameter is missing then returns a Deferred object.
-
Type
-
Deferred
|
*
Example
//retrieve the mininum price of products sold during last month
context.model('Order')
.where('orderDate').greaterOrEqual(moment().startOf('month').toDate())
.min('orderedItem/price').then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares a modular arithmetic operation
Parameters:
Name |
Type |
Description |
obj |
*
|
The value to be compared |
result |
Number
|
The result of modular expression |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Prepares a multiplication (e.g. ([field] * 0.2))
Parameters:
Name |
Type |
Description |
x |
number
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve a list of orders
context.model('Product')
.select('id','name', 'price')
//perform ((ProductData.price * 0.2)<50)
.where('price').multiply(0.2).lowerThan(50)
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares a not contains comparison (e.g. a string contains another string).
Parameters:
Name |
Type |
Description |
value |
*
|
The right operand of the expression |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Examples
//retrieve persons where the given name not contains 'ar'
context.model('Person').select(['id','givenName','familyName'])
.where('givenName').notContains('ar')
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
//The result set of this example may be:
id givenName familyName
--- --------- ----------
257 Daisy Lambert
259 Peter French
261 Kylie Jordan
263 Maxwell Hall
265 Christian Marshall
Prepares a not equal comparison.
Parameters:
Name |
Type |
Description |
obj |
*
|
The right operand of the expression |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve a list of orders with order status different than 1
context.model('Order')
.where('orderStatus').notEqual(1)
.orderByDescending('orderDate')
.list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares a typical NOT IN comparison.
Parameters:
Name |
Type |
Description |
objs |
Array
|
An array of values which represents the values to be used in expression |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve orders with order status 1 or 2
context.model('Order').where('orderStatus').notIn([1,2])
.list().then(function(result) {
//WHERE (NOT OrderData.orderStatus IN (1, 2))
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares a logical OR expression
Parameters:
Name |
Type |
Description |
attr |
string
|
The name of field that is going to be used in this expression |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//((OrderData.orderStatus=1) OR (OrderData.orderStatus=2)
context.model('Order').where('orderStatus').equal(1)
.or('orderStatus').equal(2)
.list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares an ascending sorting operation
Parameters:
Name |
Type |
Description |
attr |
string
|
The field name to use for sorting results |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
orderByDescending(attr) → {DataQueryable}
Prepares a descending sorting operation
Parameters:
Name |
Type |
Description |
attr |
string
|
The field name to use for sorting results |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Serializes the underlying query and clears current filter expression for further filter processing. This operation may be used in complex filtering.
Parameters:
Name |
Type |
Attributes |
Description |
useOr |
Boolean
|
<optional>
|
Indicates whether an or statement will be used in the resulted statement. |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve a list of order
context.model('Order')
.where('orderStatus').equal(1).and('paymentMethod').equal(2)
.prepare().where('orderStatus').equal(2).and('paymentMethod').equal(2)
.prepare(true)
//(((OrderData.orderStatus=1) AND (OrderData.paymentMethod=2)) OR ((OrderData.orderStatus=2) AND (OrderData.paymentMethod=2)))
.list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
remove(obj, callbackopt) → {Promise.<T>|*}
Removes the association between parent object and the given object or array of objects.
Parameters:
Name |
Type |
Attributes |
Description |
obj |
*
|
Array
|
|
An object or an array of objects to be disconnected from parent object |
callback |
function
|
<optional>
|
A callback function where the first argument will contain the Error object if an error occured, or null otherwise. |
- Source:
Returns:
- If callback parameter is missing then returns a Promise object.
-
Type
-
Promise.<T>
|
*
Example
//remove a user (by name) from Administrators group
var groups = context.model('Group');
groups.where('name').equal('Administrators')
.first().then(function(result) {
var group = groups.convert(result);
group.property('members').remove({ name: 'alexis.rees@example.com' }).then(function() {
done();
});
}).catch(function(err) {
done(err);
});
removeAll(callbackopt) → {Promise|*}
Removes all associations
Parameters:
Name |
Type |
Attributes |
Description |
callback |
function
|
<optional>
|
|
- Source:
Returns:
-
Type
-
Promise
|
*
* Prepares a round mathematical expression
Parameters:
Name |
Type |
Attributes |
Description |
n |
number
|
<optional>
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Initializes a full-text search expression
Parameters:
Name |
Type |
Description |
text |
string
|
A string which represents the text we want to search for |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
context.model('Person')
.search('Peter')
.select('description')
.take(25).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Selects a field or a collection of fields of the current model.
Parameters:
Name |
Type |
Attributes |
Description |
attr |
string
|
<repeatable>
|
An array of fields, a field or a view name |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Examples
//retrieve the last 5 orders
context.model('Order').select('id','customer','orderDate','orderedItem')
.orderBy('orderDate')
.take(5).list().then(function(result) {
console.table(result.records);
done(null, result);
}).catch(function(err) {
done(err);
});
//retrieve the last 5 orders by getting the associated customer name and product name
context.model('Order').select('id','customer/description as customerName','orderDate','orderedItem/name as productName')
.orderBy('orderDate')
.take(5).list().then(function(result) {
console.table(result.records);
done(null, result);
}).catch(function(err) {
done(err);
});
//The result set of this example may be:
id customerName orderDate orderedItemName
--- ------------------- ----------------------------- ----------------------------------------------------
46 Nicole Armstrong 2014-12-31 13:35:41.000+02:00 LaCie Blade Runner
288 Cheyenne Hudson 2015-01-01 13:24:21.000+02:00 Canon Pixma MG5420 Wireless Photo All-in-One Printer
139 Christian Whitehead 2015-01-01 23:21:24.000+02:00 Olympus OM-D E-M1
3 Katelyn Kelly 2015-01-02 04:42:58.000+02:00 Kobo Aura
59 Cheyenne Hudson 2015-01-02 10:47:53.000+02:00 Google Nexus 7 (2013)
//retrieve the best customers by getting the associated customer name and a count of orders made by the customer
context.model('Order').select('customer/description as customerName','count(id) as orderCount')
.orderBy('count(id)')
.groupBy('customer/description')
.take(3).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
//The result set of this example may be:
customerName orderCount
---------------- ----------
Miranda Bird 19
Alex Miles 16
Isaiah Morton 16
Disables permission listeners and executes the underlying query without applying any permission filters
Parameters:
Name |
Type |
Attributes |
Description |
value |
Boolean
|
<optional>
|
A boolean which represents the silent flag. If value is missing the default parameter is true. |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve user
context.model('User')
.where('name').equal('other@example.com')
.silent()
.first().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares a paging operation by skipping the specified number of records
Parameters:
Name |
Type |
Description |
n |
number
|
The number of records to be skipped |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve a list of products
context.model('Product')
.skip(10)
.take(10)
.list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Prepares an ends with comparison
Parameters:
Name |
Type |
Description |
obj |
*
|
The string to be searched for at the end of a field. |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Examples
//retrieve people whose given name starts with 'D'
context.model('Person')
.where('givenName').startsWith('D')
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
//Results:
id givenName familyName
--- --------- ----------
257 Daisy Lambert
275 Dustin Brooks
333 Dakota Gallagher
substr(start, lengthopt) → {DataQueryable}
Prepares a substring comparison
Parameters:
Name |
Type |
Attributes |
Description |
start |
number
|
|
The position where to start the extraction. First character is at index 0 |
length |
number
|
<optional>
|
The number of characters to extract |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Examples
//retrieve a list of persons
context.model('Person')
.select('givenName')
.where('givenName').substr(0,4).equal('Alex')
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
//Results:
givenName
---------
Alex
Alexis
Prepares a subtraction (e.g. ([field] - 4))
Parameters:
Name |
Type |
Description |
x |
number
|
*
|
|
- Inherited From:
- Source:
Returns:
//retrieve a list of orders
context.model('Product')
.select('id','name', 'price')
//perform ((ProductData.price - 50)<150)
.where('price').subtract(50).lowerThan(150)
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
-
Type
-
DataQueryable
sumOf(name, aliasopt) → {*|QueryField}
Parameters:
Name |
Type |
Attributes |
Description |
name |
string
|
|
|
alias |
string
|
<optional>
|
|
- Inherited From:
- Source:
Returns:
-
Type
-
*
|
QueryField
take(n, callbackopt) → {DataQueryable|*}
Prepares a data paging operation by taking the specified number of records
Parameters:
Name |
Type |
Attributes |
Description |
n |
Number
|
|
The number of records to take |
callback |
function
|
<optional>
|
A callback function where the first argument will contain the Error object if an error occured, or null otherwise. The second argument will contain the result. |
- Inherited From:
- Source:
Returns:
- If callback function is missing returns a promise.
-
Type
-
DataQueryable
|
*
Continues a ascending sorting operation
Parameters:
Name |
Type |
Description |
attr |
string
|
The field to use for sorting results |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
thenByDescending(attr) → {DataQueryable}
Continues a descending sorting operation
Parameters:
Name |
Type |
Description |
attr |
string
|
The field name to use for sorting results |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
title(valueopt) → {string|DataQueryable}
Gets or sets a string which represents the title of this DataQueryable instance. This title may be used in caching operations
Parameters:
Name |
Type |
Attributes |
Description |
value |
string
|
<optional>
|
The title of this DataQueryable instance |
- Inherited From:
- Source:
Returns:
-
Type
-
string
|
DataQueryable
toExpand(attr)
Converts a DataQueryable instance to an object which is going to be used as parameter in DataQueryable.expand() method
Parameters:
Name |
Type |
Description |
attr |
String
|
A string which represents the attribute of a model which is going to be expanded with the options specified in this instance of DataQueryable. |
- Inherited From:
- Source:
Example
//get customer and customer orders with options (e.g. select specific attributes and sort orders by order date)
context.model("Person")
.search("Daisy")
.expand(context.model("Order").select("id", "customer","orderStatus", "orderDate", "orderedItem").levels(2).orderByDescending("orderDate").take(10).toExpand("orders"))
.take(3)
.getItems()
.then(function (result) {
console.log(JSON.stringify(result));
done();
}).catch(function (err) {
done(err);
});
Prepares a lower case string comparison
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Prepares an upper case string comparison
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Prepares a lower case string comparison
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
//retrieve a list of persons
context.model('Person')
.where('givenName').toLocaleLowerCase().equal('alexis')
.take(5).list().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
toMD5() → {string}
Generates a MD5 hashed string for this DataQueryable instance
- Inherited From:
- Source:
Returns:
-
Type
-
string
Prepares an upper case string comparison
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Prepares a string trimming expression
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
value(callbackopt) → {Deferred|*}
Executes the underlying query and a single value.
Parameters:
Name |
Type |
Attributes |
Description |
callback |
function
|
<optional>
|
A callback function where the first argument will contain the Error object if an error occured, or null otherwise. The second argument will contain the result. |
- Inherited From:
- Source:
Returns:
-
Type
-
Deferred
|
*
Example
//retrieve the full name (description) of a person
context.model('Person')
.where('user').equal(330)
.select('description')
.value().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});
Initializes a where expression
Parameters:
Name |
Type |
Description |
attr |
string
|
A string which represents the field name that is going to be used as the left operand of this expression |
- Inherited From:
- Source:
Returns:
-
Type
-
DataQueryable
Example
context.model('Person')
.where('user/name').equal('user1@exampl.com')
.select('description')
.first().then(function(result) {
done(null, result);
}).catch(function(err) {
done(err);
});