Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface DatastoreClass

Hierarchy

  • DatastoreClass

Index

Properties

attributes

Collection of available attributes

returns

Object containing all the attributes of the DatastoreClass

ds.MyDataclass.attributes

length

length: Number

Number of entities in the datastore class

ds.MyDataclass.length

Methods

all

average

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

    For a detailled description of the method, go here

    Parameters

    Returns Number

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

createEntity

  • creates a new blank object of type Entity based on the datastore class.

    warning

    The object is created in memory and is not saved in the datastore until the save( ) method is called. If the object is deleted before being saved, it cannot be recovered.

    Example (create then save)

    var newCompany = ds.Company.createEntity() ;
    a.name = 'Wakanda';
    a.city = 'Paris' ;
    a.save() ;

    Note

    Another useful alternative way to create entities (then save) is to use the new syntax `javascript new ds.Company({ name : 'Wakanda' , city : 'Paris' }).save();

    Returns Entity

createEntityCollection

  • creates a new blank object of type EntityCollection attached to the datastore class

    warning

    = createEntityCollection do work only with Wakanda built-in DB. It does not work with MySQL / ODBC Connectors*

    Example 1

    var all = ds.Person.all(); // get all the entities
    var coll1 = ds.Person.createEntityCollection(); // create an empty unsorted entity collection
    coll1.add( all[10]); //add some entities, one of them 3 times
    coll1.add( all[9]);
    coll1.add( all[8]);
    coll1.add( all[7]);
    coll1.add( all[8]);
    coll1.add( all[8]);
    coll1; // displays the collection

    Parameters

    • Optional keepSorted: Boolean

      Boulean - True to create a SortedCollection (false by Default)

      Note

      For more information about sorted/unsorted collection, visit this page

    Returns EntityCollection

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

fromArray

  • generates entities in the datastore class where it is applied and returns the resulting entity collection

    warning

    :

    • The entities passed in the arrayValues are generated and saved when executing fromArray()
    • Wakanda automatically adds the ID number to the entity created
    • You can modify an existing entity by adding the __KEY and STAMP attributes and their respective values in arrayValues

    Example

    var arrAdd = []     // Create an empty array
    arrAdd[0] = {lastName: "Potter", firstName: "Harold", salary: 3200};
    arrAdd[1] = {lastName: "Luke", firstName: "Lucy", salary: 5300, married: true}; // 'married' is ignored if the attribute does not exist in the datastore class
    arrAdd[2] = {lastName: "Blue", firstName: "George", salary: 3200};
    var newColl = ds.Employees.fromArray(arrAdd);     // entities are created and saved
    newColl;

    Parameters

    • arrayValues: any[]

    Returns EntityCollection

    New entity collection

getCollectionPageLength

  • getCollectionPageLength(): Number
  • getCollectionPageLength returns the default page size of a dataclass.

    Returns Number

    Dataclass page size.

    Example

    myRemoteDatastore.Employees.getCollectionPageLength();

getFragmentation

  • getFragmentation(): Number

getName

  • getName(): String
  • returns the name of the datastore class to which it is applied in a string

    var nameEM = ds.Book.getName();

    Returns String

getScope

  • getScope(): String
  • returns the current scope property value of the datastore class Two values can be returned for a datastore class: (default value public)

    - "public": a public datastore class can be accessed from anywhere (including on the client side)
    • "public on server": a public on server datastore class can only be accessed on the server

    You can get more information about the Datastore Class Properties here

    Returns String

importFromJSON

  • imports all the entities stored in JSON format from the file(s) located in the importFolder folder

    The importFromJSON( ) method can be called for a:

    - Datastore: entities from all the datastore classes are imported,
    - DatastoreClass: entities from the datastore class are imported.

    Note

    This method only work with the Wakanda Built-in database (MYSQL and other Connectors are not concerned)

    warning

    :

        - This folder must contain UTF-8 text files into which each entity is described through a single JSON object
        - calculated attributes cannot be imported directly -- only their underlying attributes are imported,
        - extended datastore class entities cannot be imported,
        - related or alias attributes are not imported directly -- only primary keys values are exported,
        - you cannot import data from outside catalogs or datastores.
    
     You can refer to the [exportAsJson method description] (entitycollection.html#exportasjson) for more information about exporting/importing

    Parameters

    Returns void

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

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

  • 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

    Descrption

    The Query method description is fully described [here (entity collection part)] (entitycollection.html#query)

    Parameters

    • queryString: String
    • Rest ...valueList: any[]

    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

setAutoSequenceNumber

  • setAutoSequenceNumber(counter: Number): void

setCollectionPageLength

  • setCollectionPageLength(pageSize: Number): void
  • setCollectionPageLength sets the default dataclass page size returned by each query. This setting is only applied to the current dataclass.

    warning

    This method can only be used on Wakanda/4D remote datastore dataclasses.

    Parameters

    • pageSize: Number

      Number of entities return by each query

      Example

      myRemoteDatastore.Employees.setCollectionPageLength(80);

    Returns void

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