Methods Overview

Methods Overview

The Backend Services JavaScript SDK provides a set of methods that allows you to perform projection, sorting, filtering, paging and so on when querying fr data. Most methods can only be used with read operations.

The Backend Services JavaScript SDK utilizes Query objects to perform queries. A Query object is created by calling its constructor:

var query = new Everlive.Query();

The methods of the Query objects are fluent, i.e. one can chain them like this:

query.where().gt('age', 5).lt('age', 15).done().select('title', 'summary').order('age').take(10).skip(10);

List of Methods

The methods of a Query object are as follows:

  • where() - used for building filters. This method returns a WhereQuery object that has its own fluent methods. More about them can be found below.

  • done() - used for terminating the filtering conditions created with the where() method and there are more query methods that follow.

Projection

  • select(field1, field2, ...) - specifies what fields to be retrieved from the services.

Sorting

  • order(field) and orderDesc(field) - specify the sorting order of the item that are to be retrieved.

  • take(number) - limits the number of items to be retrieved.

  • skip(number) - specifies the number of items from a content type not to be included in the result.

Filtering

The WhereQuery type has its own methods that are used to build filters. These are:

  • eq(field, value), equal(field, value) - creates a condition where a field has the given value.
query.where().equal('name', 'Joe');
  • ne(field, value), notEqual(field, value) - creates a condition where a field has a value different from a given value.

  • gt(field, value), greaterThan(field, value) - creates a condition where a field has a value greater than a given value.

  • gte(field, value), greaterThanEqual(field, value) - creates a condition where a field has a value greater than or equal to a given value.

  • lt(field, value), lessThan(field, value) - creates a condition where a field has a value less than a given value.

  • lte(field, value), lessThanEqual(field, value) - creates a condition where a field has a value less than or equal to a given value.

  • isin(field, [value1, value2, ...]) - creates a condition where a field has a value equal to one of the given values.

query.where().isin('name', ['Joe', 'Jack']);
  • notin(field, [value1, value2, ...]) - creates a condition where a field has a value different from the given values or the field does not exist.

  • all(field, [value1, value2, ...]) - creates a condition where an array field has all the given values.

  • size(field, number) - creates a condition where an array field has the given number of items.

  • regex(field, expression), regex(field, string, flags) - creates a condition where a string field matches the given expression.

query.where().regex('name', /And.*/i);
 //or
query.where().regex('name', 'And.*', 'i');
  • startsWith(field, string, flags) - creates a condition where a string field starts with the given value.

  • endsWith(field, string, flags) - creates a condition where a string field ends with the given value.

Negation

  • not() - negates the condition that follows.
query.where().not().equal('name', 'Joe');
//is equivalent to
query.where().notEqual('name', 'Joe');

Logical

There are two additional methods that are used to create complex conditions using logical conjunction and disjunction. When such methods are not used then the conditions form a logical conjunction implicitly.

  • and() - creates a complex condition where the following conditions are operands of logical conjunction.
query.where().and().eq('name', 'Joe').eq('age', 25);
//is equivalent to 
query.where().eq('name', 'Joe').eq('age', 25);
  • or() - creates a complex condition where the following conditions are operands of logical disjunction.
query.where().or().eq('name', 'Joe').eq('age', 25);

The complex conditions are terminated with the done() method. You can skip the calling of this method if there are no following conditions.

query.where().and().eq('name', 'Joe').eq('age', 25);
 //is equivalent to 
query.where().and().eq('name', 'Joe').eq('age', 25).done();
query.where().eq('name', 'Joe').done().sort('age');

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.