Queries
Queries are used to get and filter records through a Queryable
object. Which uses lodash
to work with Array
records. The following contents are a list of available query methods.
Work with Queryable
Queryable
contains a set of immutable records and separated from the Document records. The following code demonstrates how to create a Queryable
object.
import { Queryable } from 'vasern';
const queryObj = new Queryable(data);
Get record
Find and return a record that match with lookupQuery
.
Queryable.get(lookupQuery)
Arguments
- lookupQuery ( string | Object )
- (string): match record id with
string
value - (Object): match record properties and values with
Object
properties and values
- (string): match record id with
Return
- Object: object that match with lookupQuery
- undefined if not found
Example
var foundRecord = Queryable.get({ id: "5bc592cacdAsassfs000ddddBBdbcdfb" });
Filter records
Find and return a list of records that match with lookupQuery
.
Queryable.filter(lookupQuery)
Arguments
- lookupQuery ( Object ): match record properties and values with
Object
properties and values
Return
- Array<Object>: a list of records that match with lookupQuery
Example
var records = Queryable.filter({ completed: true });
Exclude records
Excludes records that match with lookupQuery
from current Queryable dataset.
Queryable.exclude(lookupQuery)
Arguments
- lookupQuery ( Object ): match record properties and values with
Object
properties and values
Return
- Array<Object>: a list of records that match with lookupQuery
Example
var records = Queryable.exclude({ completed: true });
Order records
Re-order records list by key
.
Queryable.order(key, asc = true)
Arguments
- key ( string ): property name
- asc (boolean): allow order ascending, set to
false
for decending order.
Return
- Array<Object>: a list of reorderd records
Example
var records = Queryable.filter({ completed: true });
What's next?
Learn about Event listeners