Description of the query as it was actually performed
var mySet = ds.Employee.query("salary > :1 and employer.name = :2", 2000, "ACME", {queryPath: true})
var thePath = mySet.queryPath
Description of the query just before it is executed
var mySet = ds.Employee.query("salary > :1 and employer.name = :2", 2000, "ACME", {queryPlan: true})
var thePath = mySet.queryPlan
Adds entity collection passed in the toAdd parameter to the entity collection
var myColl = ds.Employee.createEntityCollection(); //Create an empty collection
myColl.add(ds.Employee.first()); //Add the first datastore class entity
var myQuery = ds.Employee.query("lastName == :1","H*"); //Find some employees
if(myQuery != null) //some entities were found
myColl.add(myQuery); //Add the collection itself
true
to add the collection at the end of the current collection, false
for AnyWhere
Adds the entity passed in the toAdd parameter to the entity collection
var myColl = ds.Employee.createEntityCollection(); //Create an empty collection
myColl.add(ds.Employee.first()); //Add the first datastore class entity
var entity = ds.Employee.find("lastName == :1","H*"); //Find an employee
if(entity != null) //An entity was found
myColl.add(entity); //Add the entity
true
to add the collection at the end of the current collection, false
for AnyWhere
The and( ) method compares the entity collection to which it is applied and the collection2 and returns a new entity collection that contains only the entities that are referenced in both collections. You can compare sorted and/or unsorted entity collections. The resulting collection is always unsorted.
Collection to compare with
Resulting (unsorted) entity collection
var coll1 = ds.Employee.query("name =:1", "Jones") ;
var coll2 = ds.Employee.query("city=:1", "New York") ;
var coll3 = coll1.and(coll2);
The average method returns the arithmetic average of all the non-null values of attribute for the datastore class or entity collection
string
Attribute whose average you want to calculate
boolean
Use only entities that have different values
Number Arithmetic average of attribute values
Compute performs, in a single call, all the statistical calculations on the attribute or list of attributes passed as the parameter for the datastore class or entity collection
DatastoreClassAttribute,String Attribute(s) for which you want to perform statistical calculations
Boolean Compute distinct calculations - false
by default
Object containing the following calculations :
- average Arithmetic average
- averageDistinct Average taking only distinct values into account
- count Number of values
- countDistinct Number of distinct values
- max Maximum value
- min Minimum value
- sum Sum
- sumDistinct Sum taking only distinct values into account
Compute performs, in a single call, all the statistical calculations on the attribute or list of attributes passed as the parameter for the datastore class or entity collection
DatastoreClassAttribute,String Attribute(s) for which you want to perform statistical calculations
DatastoreClassAttribute,String Attribute(s) on which you want to have subtotal breaks
Object containing all the calculations performed and subtotals
var stats = ds.Sales.all().compute("benefit, revenues", "country, month");
// compute `benefit`and `revenues` values of a Sales class grouped by country and month
// for more convenience the returned object can be converted into an array
stats.toArray();
The Count() method returns the number of entities contained in the entity collection or datastore class
DatastoreClassAttribute,String Attribute whose value must not be null
Boolean Default false
Use only entities that have different values
Number of entities in the collection or Dataclass
The distinctPaths()
method returns an array of all paths to the given object
type attribute properties.
DatastoreClassAttribute The indexed object attribute name
A sorted array of strings
The distinctValues()
method creates an array and returns in it all the distinct values stored in attribute for the entity collection or datastore class
DatastoreClassAttribute Attribute for which you want to get the list of distinct values
Array containing the list of distinct values
//In our example, we want to return the total number of different jobs in the same company:
var employer = ds.Company.find( "name == :1", "WAKANDA" ); // find the company by its name
var allEmp = ds.Employee.query("comp == :1", employer); // create an entity collection containing all the employees in a company
// 'comp' is a relation attribute in Employee
var jobNb = allEmp.distinctValues("jobName").length; //`jobName` is a DatastoreClassAttribute of Employee
// In a "keywords" object attribute of an Article datastore class, you store the page numbers for each keyword in a "pages" array.
// You want to know all pages that contain at least one keyword
var arr = ds.Article.all().distinctValues("keywords.pages[]");
exports all the entities stored in the object for which it is called in JSON format It can be called for a :
- datastore
- DatastoreClass
- EntityCollection
Folder Folder where you want to export the collection.
Number Maximum number of files per Folder
Number Size limit vamue of export files (in KB)
Number Size limit (in bytes) velow which the contents of a BLOB or Picture attribute are embedded into the main file
exports all the entities stored the object for which it is called in SQL format It can be called for a :
- datastore
- DatastoreClass
- EntityCollection
Folder Folder where you want to export the collection.
Number Maximum number of files per Folder
Number Size limit vamue of export files (in KB)
Number Size limit (in bytes) velow which the contents of a BLOB or Picture attribute are embedded into the main file
Search operation in a the DatastoreClass or EntityCollection that returns the first entity
found in an object of type Entity
The find( ) method is equivalent to executing a query( ) followed by retrieving the first entity:
For more details and exemples check the Query method section
ds.Employee.find( "name == DOE");
ds.Employee.find( 'name ==:1', "DOE");
Value(s) to compare when using placeholders
The first found entity in the collection
Returns the entity in the first position of the entity collection or datastore class
ds.Employee.query('ID > 2').first() //exemple1
ds.Company.first() //exemple2
Executes the callbackFn function on each entity in the entity collection(or Dataclass) in ascending order
Function Handler function to invoke for each entity in the collection
The callbackFn function accepts two parameters: function (
thisArg
, iterator
)
thisArg
, represents the entity currently being processed. When it is executed, the function receives in this parameter the entity on which it iterates (the parameter is used like the keyword this
). You can then perform any type of operation on the values of the entity.iterator
, is the iterator. When it is executed, the function receives in this parameter the position of the element currently being processed in the entity collection. You can use it, for example, to display a counter.
Returns the datastore class (object of the DatastoreClass type) of the entity collection.
To get the DataClass name displayed in must be followed by the getName() or toString() api
- ds.MyDataClass.all().getDataClass().toString() //to a collection with toString
- ds.MyDataClass.first().getDataClass().getName() // to an entity with getName()
Another example on a model event :
// In the onInit event of an extended datastore class, you want to fill in the 'category' attribute the name of the derived class.
// You can write:
model.Manager.events.init = function(event)
{
//get the name of the class of the entity
var myType = this.getDataClass().getName();
//fill it in the category attribute
this.category = myType;
};
Returns the maximum value among all the values of attribute in the entity collection or datastore class
DatastoreClassAttribute Attribute for which you want to get the highest value.
Number Highest value of attribute
//We want to find the highest salary among all the female employees:
var fColl = ds.Employee.query("gender == :1","female");
var maxFSalary = fColl.max("salary");
var value = ds.MyClass.all().max("objectAtt.prop") //Highest of all prop attribute values
returns the lowest (or minimum) value among all the values of attribute in the entity collection or datastore class
DatastoreClassAttribute Attribute for which you want to get the lowest value.
Number Lowest value of attribute
//We want to find the lowest salary among all the female employees:
var fColl = ds.Employee.query("gender == :1","female");
var maxFSalary = fColl.min("salary");
var value = ds.MyClass.all().min("objectAtt.prop") //Lowest of all prop attribute values
Minus method excludes from the entity collection to which it is applied the entities that are in the collection2 and returns the resulting entity collection
The collection to substract
Resulting EntityCollection (unsorted)
creates a new entity collection that contains all the entities from the entity collection to which it is applied and all the entities from the collection2 entity collection
Merged resulting entity collection (unsorted)
The orderBy method sorts the entities in the entity collection or datastore class and returns a new sorted entity collection
DatastoreClassAttribute Attribute(s) to be sorted and (if String) order by direction(s)
string asc
(by default
) for ascending sort / desc
for descending.
searches all the entities in the datastore class or entity collection using the search criteria specified in queryString and returns a new collection containing the entities found
search criteria
Object query options
Two different syntaxes are allowed.
ds.People.query("lastname == dubois and firstname == jules");
ds.People.query("lastname== :1 AND firstname == :2" , "dubois" , "jules");
Options object description
false
Returs the performed queryfalse
Returns the planned queryfalse
Allow direct JavaScript execution in the query string. The queryString must be prefixed with the $
symbol
Symbol to use | Comparison | Comment |
---|---|---|
== | like | supports the wildcard (*), neither case-sensitive nor diacritic |
=== | Equal to | supports the wildcard (*), neither case-sensitive nor diacritic |
in | Is in Array | |
!= | Not Like | |
!== | Not Equal to | |
> | Greater than | |
>= | Greater than or equal to | |
< | Less han | |
<= | Less than or equal to | |
begin | Begins with | "Begin t" is thus equivalent to "== t*" |
%% | Contains keyword | works with text or picture type |
=% | Matches | Use with JavaScript Regex |
!=% | Does not match | Use with JavaScript Regex |
| Symbol to use | operation |
|---------------|-----------|
| & | AND |
| | | OR |
| ! | NOT |
| ^ | EXCEPT |
Permanently removes entities from the datastore
// Applied to a Dataclass
ds.Dataclass1.remove();
// Applied to a collection
ds.Dataclass1.query('ID > 3 & ID < 5').remove();
// Applied to an entity
ds.Dataclass1.first().remove();
// Applied at the Model level (Entity method on the Customer dataclass)
model.Customer.entityMethods.remove = function() {
this.remove();
};
The slice()
method returns a shallow copy of a portion of a collection into a new collection object selected from begin to end (end not included). The original collection will not be modified.
Zero-based index at which to begin extraction
Zero-based index before which to end extraction. slice
extracts up to but not including end.
slice
does not alter the original collection. It returns a shallow copy of elements from the original collection.
var originalCollection = ds.Employees.query("ID < 100").orderBy("salary desc");
// Get a copy of the collection
var copyCatColl = originalCollection.slice();
// Get the first 10 and give them a good raise
var firstTenColl = originalCollection.slice(0,10);
// Get the last 10
var lastTenColl = originalCollection.slice(-10);
// Exclude first and last 10 and give them a decent raise
var middleGuysColl = originalCollection.slice(10, -10);
returns the sum (i.e., total of all the values) of attribute for the datastore class or entity collection
false
by Default Use only entities that have different values
var highSalaries = ds.Employees.query("salary > 30000").sum("salary" , true);
var propSum = ds.MyClass.all().sum("objectAtt.prop") //sum of all prop attribute values
The toArray() method creates and returns a JavaScript array where each element is an object containing a set of properties and values corresponding to the attribute names and values for a datastore class or an entity collection
DatastoreClassAttribute List of attributes to return as array or "" to return all attributes
string list of attributes used for the sort
boolean Include the entity key and stamp false
by default
number Position of starting entity to return
number Number of entities to return
Array containing attributes and values of datastore class or entity collection
You can of course navigate through dataclasses via relation attributes.
In this scenario you can even limit the number of related entities fetched by passing RelatedAttribure: N
(where N represents the number of sub elements)
// - Retrieve the first five students.
// - Limit the number of courses per student to five.
// - Sort arrays by the student's first name and sort course sub-arrays by subject name. Both in ascending order.
// - skip the 1st result
var sel = ds.Student.all();
var myArray = sel.toArray("fullName, Course:5, Course.matter, Course.teacher.fullName", "firstName, Course.matter", 1, 5);
`
returns a string representation of the entity or entity collection
ds.Dataclass1.query('ID > 3').toString() // applied to a collection
ds.Dataclass1.first().toString() // applied to an entity
Number of entities in the entity collection.
var myCount = ds.Dataclass.length ;