Query
The default structure of objects used to represent queries.
{filter: FILTER, sort: SORT, page: PAGE}
The following is an example query:
{
// Selects only the todos that match.
filter: {
complete: false
},
// Sort the results of the selection
sort: "name desc",
// Selects a range of the sorted result
page: {start: 0, end: 19}
}
Parameters
- filter
{Object}
:The
filter
property is an object of property names to values like:{ filter: { age: {$gt: 21}, name: ["Justin","Ramiya"] } }
The Comparison Operators (
$eq
,$gt
,$gte
,$in
,$lt
,$lte
,$ne
,$nin
) are available withinfilter
. - sort
{String}
:The
sort
property is an optional value specifying:- the property used to sort the results of a query, and
- the direction of the sort (start the value with
-
for descending).
The sort property is specified as a string like
sort: "age"
.sort: "age"
will return results ascending by theage
property.sort: "-age"
will return results descending by theage
property.This format follows JSON API's recommendations on sorting. However,
can-query-logic
can only sort by a single property currently.The
sort
property defaults to"ID_PROPERTY"
whereID_PROPERTY
is the first identity property returned by identityKeys. This is usually the first identity value on the schema passed tonew QueryLogic()
:new QueryLogic({ identity: ["_id"] }).identityKeys() //-> ["_id"]
- page
{Object}
:The optional
page
property selects a range of the sorted result. It's values are inclusive and begin at0
. This means that:{start: 0, end: 1}
- Selects the first two records in the result.{start: 10, end: 19}
- Selects 10 records after the first 10 records.
The
start
value defaults to0
and theend
value defaults toInfinity
. This means that:{end: 99}
- Selects the first 100 records.{start: 100}
- Selects all records after the first 100.