Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface EntityCollection

Hierarchy

  • EntityCollection

Index

Properties

length

length: Number

Number of entities in the entity collection.

var myCount = ds.Dataclass.length ;

queryPath

queryPath: String

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
param
returns

An object describing how the query is performed

queryPlan

queryPlan: String

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
param
returns

object containing the detailed description of the query just before it was executed (i.e., the planned query).

Methods

add

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

    By default, if the atTheEnd parameter is omitted or False, the original type of the entity collection is left unchanged.

    Parameters

    • toAdd: EntityCollection
    • Optional atTheEnd: Boolean

      true to add the collection at the end of the current collection, false for AnyWhere

    Returns void

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

    By default, if the atTheEnd parameter is omitted or False, the original type of the entity collection is left unchanged.

    Parameters

    • toAdd: Entity
    • Optional atTheEnd: Boolean

      true to add the collection at the end of the current collection, false for AnyWhere

    Returns void

and

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

    Parameters

    Returns EntityCollection

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

average

  • The average method returns the arithmetic average of all the non-null values of attribute for the datastore class or entity collection

    warning

    By default distinct : false

    Example 1

    var averageSalary = ds.Employee.average("salary", true);
    var mySet = ds.Employee.query( "salary > :1", averageSalary);

    Example 2 - With Object Attribute dimensions

    var coll = ds.Box.query("dimensions.bLength > :1", 200);
    var vAvg = coll.average("dimensions.bWidth");

    Parameters

    • attribute: DatastoreClassAttribute

      string Attribute whose average you want to calculate

    • Optional distinct: Boolean

      boolean Use only entities that have different values

    Returns Number

    Number Arithmetic average of attribute values

compute

  • 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

    warning

    If you pass more than one attribute and enable the Distinct calculations, they will be valid only for the first attribute.

    Example 1 - Compute Multi Attributes with Distinct

     var calculations = ds.Employee.compute("age, salary", true); //the Distinct operations will be performed only on the `age` attribute
     var stats = "Average age ="+ calculations.age.averageDistinct+" Total salary ="+calculations.salary.sum);

    Parameters

    • attribute: DatastoreClassAttribute

      DatastoreClassAttribute,String Attribute(s) for which you want to perform statistical calculations

    • Optional distinct: Boolean

      Boolean Compute distinct calculations - false by default

    Returns Object

    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

    Parameters

    • attribute: DatastoreClassAttribute

      DatastoreClassAttribute,String Attribute(s) for which you want to perform statistical calculations

    • Optional groupBy: DatastoreClassAttribute

      DatastoreClassAttribute,String Attribute(s) on which you want to have subtotal breaks

    Returns Object

    Object containing all the calculations performed and subtotals

    Example 1 - Compute with groupBy

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

count

  • The Count() method returns the number of entities contained in the entity collection or datastore class

    warning

    distinct parameter is ignored if you do not pass the attribute parameter

    Example 1

    ds.DataClass1.query('name > 1*').count('name2', true)

    Example 2 - Count on object attribute

    var vCount = ds.MyClass.all().count("objectAtt.prop") // `objectAtt` is an object attribute with a `prop` property

    Parameters

    • attribute: DatastoreClassAttribute

      DatastoreClassAttribute,String Attribute whose value must not be null

    • Optional distinct: Boolean

      Boolean Default false Use only entities that have different values

    Returns Number

    Number of entities in the collection or Dataclass

distinctPaths

  • The distinctPaths() method returns an array of all paths to the given object type attribute properties.

    warning

    The object attribute whose name is given as a parameter must be indexed

    Example: Get a list of all distinct paths available

    var allProducts = ds.Products.all();
    var allPaths = allProducts.distinctPaths("type"); //job is a DatastoreClassAttribute of Employee
    // Returns [
    "computer",
    "computer.desktop",
    "computer.laptop",
    "pen",
    "phone",
    "phone.smartphone"
    ]

    Parameters

    Returns any[]

    A sorted array of strings

distinctValues

  • The distinctValues() method creates an array and returns in it all the distinct values stored in attribute for the entity collection or datastore class

    Parameters

    • attribute: DatastoreClassAttribute

      DatastoreClassAttribute Attribute for which you want to get the list of distinct values

    Returns any[]

    Array containing the list of distinct values

    Example 1

    //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

    Example 2 - distinctValues with Object Attributes.

    // 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[]");

exportAsJSON

  • exportAsJSON(exportFolder: WAKFolderInstance, numFiles?: Number, fileLimitSize?: Number, attLimitSize?: Number): void
  • 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
    warning

    :

    Parameters

    • exportFolder: WAKFolderInstance

      Folder Folder where you want to export the collection.

    • Optional numFiles: Number

      Number Maximum number of files per Folder

    • Optional fileLimitSize: Number

      Number Size limit vamue of export files (in KB)

    • Optional attLimitSize: Number

      Number Size limit (in bytes) velow which the contents of a BLOB or Picture attribute are embedded into the main file

    Returns void

exportAsSQL

  • exportAsSQL(exportFolder: WAKFolderInstance, numFiles?: Number, fileLimitSize?: Number, attLimitSize?: Number): void
  • exports all the entities stored the object for which it is called in SQL format It can be called for a :

    - datastore
    - DatastoreClass
    - EntityCollection
    warning

    :

    Parameters

    • exportFolder: WAKFolderInstance

      Folder Folder where you want to export the collection.

    • Optional numFiles: Number

      Number Maximum number of files per Folder

    • Optional fileLimitSize: Number

      Number Size limit vamue of export files (in KB)

    • Optional attLimitSize: Number

      Number Size limit (in bytes) velow which the contents of a BLOB or Picture attribute are embedded into the main file

    Returns void

find

  • find(queryString: String, valueList: any[], options: Object): Entity
  • Search operation in a the DatastoreClass or EntityCollection that returns the first entity found in an object of type Entity

    Important :

    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

    Example1 : With QueryString syntax

    ds.Employee.find( "name == DOE");

    Example2 : With placeholders syntax

    ds.Employee.find( 'name ==:1', "DOE");

    Parameters

    • queryString: String
    • valueList: any[]

      Value(s) to compare when using placeholders

    • options: Object

    Returns Entity

    The first found entity in the collection

first

  • Returns the entity in the first position of the entity collection or datastore class

    Example

    ds.Employee.query('ID > 2').first()  //exemple1
    ds.Company.first()  //exemple2

    Returns Entity

forEach

  • forEach(callbackFn: Function): void
  • Executes the callbackFn function on each entity in the entity collection(or Dataclass) in ascending order

    warning

    The forEach( ) method includes an optimized mechanism that triggers the entity to be saved automatically if it has been modified, and not saved when it hasn't. You can however call the save( ) method anyway to manage any errors in a try/catch structure. (In this case the call is detected by Wakanda and the entity is not saved a second time)

    Example

     // We want to give a 5% raise to all employees with a salary less than 5,000.
    mySet = ds.Employee.query('salary < 5000') ;
    mySet.forEach(
    function( emp ) {
    emp.salary *= 1.05;
    // unnecessary to save modification forEach does it automatically when needed
    });

    Parameters

    • callbackFn: Function

      Function Handler function to invoke for each entity in the collection The callbackFn function accepts two parameters: function (thisArg, iterator)

      • The first parameter, 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.
      • The second (optional) parameter, 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 void

getDataClass

  • 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

    Example

    - 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 DatastoreClass

max

  • Returns the maximum value among all the values of attribute in the entity collection or datastore class

    Parameters

    • attribute: DatastoreClassAttribute

      DatastoreClassAttribute Attribute for which you want to get the highest value.

    Returns Number

    Number Highest value of attribute

    Example 1

    //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");

    Example 2 - Max with object attributes

    var value = ds.MyClass.all().max("objectAtt.prop") //Highest of all prop attribute values

min

  • returns the lowest (or minimum) value among all the values of attribute in the entity collection or datastore class

    Parameters

    Returns Number

    Number Lowest value of attribute

    Example 1

    //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");

    Example 2 - Min with object attributes

    var value = ds.MyClass.all().min("objectAtt.prop") //Lowest of all prop attribute values

minus

or

orderBy

  • The orderBy method sorts the entities in the entity collection or datastore class and returns a new sorted entity collection

    info

    You can pass from 1 to x attributes separated by commas

    Example1 orderBy with Mutliple Attributes

     // This example performs a simple search and returns an entity collection that has been sorted on two attributes, the first in descending order
     var mySet = ds.People.query("salary > 10000");
     var mySet2 = mySet.orderBy("salary desc,city");

    Example2 orberBy with a relation attribute

    // This example sorts employees with a salary greater than 10,000 by the city where their company is located, using a relation attribute
    var mySet = ds.People.query("salary > 10000");
    mySet = mySet.orderBy(ds.People.employer.city); // `employer` is a relation attribute

    Example3 orberBy with object attributes

    ds.MyClass.all().orderBy("objectAtt.prop desc")

    Parameters

    • attributeList: DatastoreClassAttribute

      DatastoreClassAttribute Attribute(s) to be sorted and (if String) order by direction(s)

    • Optional sortOrder: String

      string asc (by default) for ascending sort / desc for descending.

    Returns EntityCollection

query

  • query(queryString: String, valueList: any[], options?: Object): EntityCollection
  • 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

    Parameters

    • queryString: String

      search criteria

    • valueList: any[]
    • Optional options: Object

      Object query options

      Important Note

      Two different syntaxes are allowed.

      • Option 1 : Pass a valid queryString :
        ds.People.query("lastname == dubois and firstname == jules");
      • Option 2 : Use placeholders (useful when using variables) :
        ds.People.query("lastname== :1 AND firstname == :2" , "dubois" , "jules");

      Options object description

      • queryPath : boolean; default false Returs the performed query
      • queryPlan : boolean; default false Returns the planned query
      • allowJavascript : boolean default false Allow direct JavaScript execution in the query string. The queryString must be prefixed with the $ symbol

      Comparators

      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

      OPERATORS

      | Symbol to use | operation |
      |---------------|-----------|
      | &             | AND       |
      | |             | OR        |
      | !             | NOT       |
      | ^             | EXCEPT    |

      EXAMPLES

      Click __Here__ to Expand Simple placeholders ```javascript //This example selects suppliers whose name contains "bob": var coll = ds.Supplier.query( "name == :1", "*bob*") // This example selects suppliers whose name does not begin with the letter T: var coll = ds.Supplier.query( "name not like :1", "T*") //This example selects suppliers whose name begins with "Sm" and ends with "th": var coll = ds.Supplier.query( "name == :1", "Sm*th") //This example selects employees hired before November 13, 2011: var emp = ds.Employee.query( "dateHired <= :1", 2011-11-12T23:00:00Z) //The following example finds the entities of American, Spanish and German customers: var coll = ds.Customer.query( "country in :1", ['US','SP','GM']); ``` Multi placeholders and variables ```javascript // The following example finds all articles containing at least one keyword from a list and then gets all the articles written by the same authors: var arrKey= ["finance", "money" , "financial" , "economic"]; var coll1 = ds.Article.query("keywords in :1" , arrKey); // finds all articles containing one or several keywords var coll2 = ds.Article.query( "author in :1" , coll1.author) ; // and finds all articles written by the authors // found in the first query results ``` With Options parameters **queryPath & queryPlan options** ```javascript var mySet = ds.Employee.query("age < :1 or worksFor.name = :2 and ID < :3", 40, "Apple", 8, {queryPath:true, queryPlan:true}); var arrComp = [mySet.queryPlan,mySet.queryPath]; arrComp; ``` **allowJavascript options** ```javascript ////exemple1 ds.Employee.query("$(this.name.length == this.firstname.length)", { allowJavascript: true }) ``` ```javascript // exemple2 ds.Company.query("name = :1 and city= :2 and $(myString.indexOf(activity) != -1)", "Acme", "London", { allowJavascript: true }) ```

    Returns EntityCollection

remove

  • remove(): void
  • Permanently removes entities from the datastore

    • When you apply it to an entity collection, it removes the entities belonging to that entity collection,
    • When you apply it to a datastore class, it removes all the entities in the datastore class.

    Examples

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

    Returns void

slice

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

    Parameters

    • Optional begin: Number

      Zero-based index at which to begin extraction

    • Optional end: Number

      Zero-based index before which to end extraction. slice extracts up to but not including end.

    Returns EntityCollection

    slice does not alter the original collection. It returns a shallow copy of elements from the original collection.

    Examples

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

sum

  • returns the sum (i.e., total of all the values) of attribute for the datastore class or entity collection

    Parameters

    • attribute: DatastoreClassAttribute
    • Optional distinct: Boolean

      false by Default Use only entities that have different values

      Example 1

       var highSalaries = ds.Employees.query("salary > 30000").sum("salary" , true);

      Example2 With Object attributes

      var propSum = ds.MyClass.all().sum("objectAtt.prop") //sum of all prop attribute values

    Returns Number

toArray

  • toArray(attributeList: DatastoreClassAttribute, sortList?: String, key?: Boolean, skip?: Number, top?: Number): any[]
  • 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

    Parameters

    • attributeList: DatastoreClassAttribute

      DatastoreClassAttribute List of attributes to return as array or "" to return all attributes

    • Optional sortList: String

      string list of attributes used for the sort

    • Optional key: Boolean

      boolean Include the entity key and stamp false by default

    • Optional skip: Number

      number Position of starting entity to return

    • Optional top: Number

      number Number of entities to return

    Returns any[]

    Array containing attributes and values of datastore class or entity collection

    Note

    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)

    EXAMPLES

    Click to Expand ### Simple case ```javascript var myArray = ds.Employee.toArray("firstName,lastName,salary"); // myArray[0] contains {firstName: 'John', lastName: 'Smith', salary: 5000} ``` ### To get all the attributes from a collection ```javascript var myColl = ds.Employee.query("salary >= 6000 order by salary asc"); var myArray = myColl.toArray(""); // return all attributes ``` ### Example with relations and options (key, skip , top) ```javascript var myArray = ds.Employee.toArray("name, employer.name, employer.location", true, 0 , 1) // employer is a relation attribute related to another dataclass // myArray[0] contains { __KEY: '0', __STAMP: 2,name: 'Smith', employer: {name: 'ACME', location: 'Memphis'}} ``` ### Example with Sort, and Sub filtered Relations (three levels) ```javascript

    // - 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); `

toString

  • toString(): String
  • returns a string representation of the entity or entity collection

    Example

    ds.Dataclass1.query('ID > 3').toString()  // applied to a collection
    ds.Dataclass1.first().toString() // applied to an entity

    Returns String