Class: Query

query.Query()

An abstract Query which allows retrieving results

Constructor

new Query()

Source:

Members

(readonly) entityManager :EntityManager

The owning EntityManager of this query

Type:
Source:

(readonly) resultClass :Class.<T>

The result class of this query

Type:
  • Class.<T>
Source:

Methods

ascending(field) → {this}

Add an ascending sort for the specified field to this query

Parameters:
Name Type Description
field string

The field to sort

Source:
Returns:

The resulting Query

Type
this

count(doneCallbackopt, failCallbackopt) → {Promise.<number>}

Execute the query that returns the matching objects count.

Parameters:
Name Type Attributes Description
doneCallback query.Query~countCallback <optional>

Called when the operation succeed.

failCallback query.Query~failCallback <optional>

Called when there is a server-side error

Source:
Returns:

The total number of matched objects

Type
Promise.<number>

descending(field) → {this}

Add an decending sort for the specified field to this query

Parameters:
Name Type Description
field string

The field to sort

Source:
Returns:

The resulting Query

Type
this

eventStream(optionsopt, onNextopt, onErroropt, onCompleteopt) → {Subscription}

Returns a subscription that handles change events for a real-time query.

The underlying stream object is hidden. To create multiple subscriptions on the same stream, create the stream
object first and then subscribe to the stream (see the other signature #eventStream(options)).

Parameters:
Name Type Attributes Description
options Object <optional>

options to narrow down the events you will receive

Properties
Name Type Attributes Default Description
initial boolean <optional>
true

whether or not you want to receive the initial result set (i.e. the
entities matching the query at subscription time)

matchTypes string | Array.<string> <optional>
['all']

the match types you are interested in; accepts the
default ('all'/['all']) or any combination of 'match', 'add', 'change', 'changeIndex' and 'remove'

operations string | Array.<string> <optional>
['any']

the operations you are interested in; accepts the
default ('any'/['any']) or any combination of 'insert', 'update', 'delete' and 'none'

onNext query.Query~nextEventCallback <optional>

Called when an event is received

onError query.Query~failCallback <optional>

Called when there is a server-side error

onComplete query.Query~completeCallback <optional>

Called when the network connection is closed (e.g. because of
lost Wi-Fi connection)

Source:
Returns:

a real-time query subscription

Type
Subscription

eventStream(optionsopt) → {Observable.<RealtimeEvent.<T>>}

Returns an observable that receives change events for a real-time query

Multiple subscriptions can be created on top of this observable:


var query = DB.Todo.find();
var options = { ... };
var stream = query.eventStream(options);
var sub = stream.subscribe(onNext, onError, onComplete);
var otherSub = stream.subscribe(otherOnNext, otherOnError, otherOnComplete);
Parameters:
Name Type Attributes Description
options Object <optional>

options to narrow down the events you will receive

Properties
Name Type Attributes Default Description
initial boolean <optional>
true

whether or not you want to receive the initial result set (i.e. the
entities matching the query at subscription time)

matchTypes string | Array.<string> <optional>
['all']

the match types you are interested in; accepts the
default ('all'/['all']) or any combination of 'match', 'add', 'change', 'changeIndex' and 'remove'

operations string | Array.<string> <optional>
['any']

the operations you are interested in; accepts the
default ('any'/['any']) or any combination of 'insert', 'update', 'delete' and 'none'

Source:
Returns:

an observable

Type
Observable.<RealtimeEvent.<T>>

eventStream(onNextopt, onErroropt, onCompleteopt) → {Subscription}

Returns a subscription that handles change events for a real-time query.

The underlying stream object is hidden. To create multiple subscriptions on the same stream, create the stream
object first and then subscribe to the stream (see the other signature #eventStream(options)).

Parameters:
Name Type Attributes Description
onNext query.Query~nextEventCallback <optional>

Called when an event is received

onError query.Query~failCallback <optional>

Called when there is a server-side error

onComplete query.Query~completeCallback <optional>

Called when the network connection is closed (e.g. because of
lost Wi-Fi connection)

Source:
Returns:

a real-time query subscription

Type
Subscription

limit(limit) → {this}

Sets the limit of this query, i.e hox many objects should be returnd

Parameters:
Name Type Description
limit number

The limit of this query

Source:
See:
Returns:

The resulting Query

Type
this

offset(offset) → {this}

Sets the offset of the query, i.e. how many elements should be skipped

Parameters:
Name Type Description
offset number

The offset of this query

Source:
See:
Returns:

The resulting Query

Type
this

resultList(doneCallbackopt, failCallbackopt) → {Promise.<Array.<T>>}

Execute the query and return the query results as a List

Note: All local unsaved changes on matching objects, will be discarded.

Parameters:
Name Type Attributes Description
doneCallback query.Query~resultListCallback <optional>

Called when the operation succeed.

failCallback query.Query~failCallback <optional>

Called when the operation failed.

Source:
Returns:

A promise that will be resolved with the query result as a list

Type
Promise.<Array.<T>>

resultList(optionsopt, doneCallbackopt, failCallbackopt) → {Promise.<Array.<T>>}

Execute the query and return the query results as a List

Note: All local unsaved changes on matching objects, will be discarded.

Parameters:
Name Type Attributes Description
options Object <optional>

The query options

Properties
Name Type Attributes Default Description
depth number | boolean <optional>
0

The object depth which will be loaded. Depth 0 load only the found
objects, true loads the objects by reachability.

doneCallback query.Query~resultListCallback <optional>

Called when the operation succeed.

failCallback query.Query~failCallback <optional>

Called when the operation failed.

Source:
Returns:

A promise that will be resolved with the query result as a list

Type
Promise.<Array.<T>>

resultStream(optionsopt, onNextopt, onErroropt, onCompleteopt) → {Subscription}

Returns a subscription that handles the complete real-time query result

The full result is received initially (i.e. on subscription) and on every change.

The underlying stream object is hidden. To create multiple subscriptions on the same stream, create the stream
object first and then subscribe to the stream (see the other signature #resultStream(options)).

Parameters:
Name Type Attributes Description
options Object <optional>

additional options

Properties
Name Type Attributes Default Description
reconnects number <optional>
-1

the number of times that a real-time query subscription should be renewed
after connection loss, before it is downgraded to a regular query that does not maintain itself; negative numbers
represent infinite reconnection attempts

onNext query.Query~nextResultCallback <optional>

Called when the query result changes in any way

onError query.Query~failCallback <optional>

Called when there is a server-side error

onComplete query.Query~completeCallback <optional>

Called when the network connection is closed (e.g. because of
network timeout or lost Wi-Fi connection) and the specified number of reconnects have been exhausted; will never be
called when infinite reconnects are configured (default)

Source:
Returns:

a real-time query subscription handling complete query results.

Type
Subscription

resultStream(onNextopt, onErroropt) → {Subscription}

Returns a subscription that handles the complete real-time query result

The full result is received initially (i.e. on subscription) and on every change.

The underlying stream object is hidden. To create multiple subscriptions on the same stream, create the stream
object first and then subscribe to the stream (see the other signature #resultStream(options)).

As the real-time query will reconnect infinitely often, there is no onComplete callback. (In other words, the
observable will never complete.)

Parameters:
Name Type Attributes Description
onNext query.Query~nextResultCallback <optional>

Called when the query result changes in any way

onError query.Query~failCallback <optional>

Called when there is a server-side error

Source:
Returns:

a real-time query subscription handling complete query results.

Type
Subscription

resultStream(optionsopt) → {Observable.<Array.<T>>}

Returns an observable that receives the complete real-time query result

The full result is received initially (i.e. on subscription) and on every change.

var query = DB.Todo.find();
var stream = query.resultStream();
var sub = stream.subscribe(onNext, onError, onComplete);
var otherSub = stream.subscribe(otherOnNext, otherOnError, otherOnComplete);

Parameters:
Name Type Attributes Description
options Object <optional>

additional options

Properties
Name Type Attributes Default Description
reconnects number <optional>
-1

the number of times that a real-time query subscription should be renewed
after connection loss, before it is downgraded to a regular query that does not maintain itself; negative numbers
represent infinite reconnection attempts

Source:
Returns:

an observable on which multiple subscriptions can be created on

Type
Observable.<Array.<T>>

singleResult(doneCallbackopt, failCallbackopt) → {Promise.<?T>}

Execute the query that returns a single result

Note: All local unsaved changes on the matched object, will be discarded.

Parameters:
Name Type Attributes Description
doneCallback query.Query~singleResultCallback <optional>

Called when the operation succeed.

failCallback query.Query~failCallback <optional>

Called when the operation failed.

Source:
Returns:

A promise that will be resolved with the query result as a single result

Type
Promise.<?T>

singleResult(optionsopt, doneCallbackopt, failCallbackopt) → {Promise.<?T>}

Execute the query that returns a single result

Note: All local unsaved changes on the matched object, will be discarded.

Parameters:
Name Type Attributes Description
options Object <optional>

The query options

Properties
Name Type Attributes Default Description
depth number | boolean <optional>
0

The object depth which will be loaded. Depth 0 load only the found
object, true loads the objects by reachability.

doneCallback query.Query~singleResultCallback <optional>

Called when the operation succeed.

failCallback query.Query~failCallback <optional>

Called when the operation failed.

Source:
Returns:

A promise that will be resolved with the query result as a single result

Type
Promise.<?T>

sort(sort) → {this}

Sets the sort of the query and discard all existing paramaters

Parameters:
Name Type Description
sort Object.<string, number>

The new sort of the query which is an object whose keys are fields and the
values are either +1 for ascending order or -1 for descending order

Source:
See:
Returns:

The resulting Query

Type
this