Realm Query
A query builder for realm.js inspired of Realm Java's query engine.
https://realm.io/docs/java/latest/#queries
Installation
$ npm install --save realm-query# or$ yarn add realm-query
Usage
const RealmQuery = ;const realm = ...; // Way 1let query = RealmQuery ; // get objects// query.toString() = name CONTAINS[c] "phu" AND (id == 1001 OR id == 1002)let results = realm; // Way 2. use lib to get objectslet results = RealmQuery // Complex querylet results = RealmQuery // It will query like this// name CONTAINS[c] "phu" AND ((id == 1001 OR id == 1002) OR (age >= 20 AND age <= 45))// and sort by id desc
API
-
#### average(fieldName: string): number Returns the average of a given field
-
#### beginGroup(): RealmQuery Begin grouping of conditions ("left parenthesis")
-
#### beginsWith(fieldName: string, value: string, casing?: boolean): RealmQuery Condition that the value of field begins with the specified string
-
#### between(fieldName: string, from: number|date, to: number|date): RealmQuery Between condition
-
#### contains(fieldName: string, value: string, casing?: boolean): RealmQuery Condition that value of field contains the specified substring
-
#### count(): number Counts the number of objects that fulfill the query conditions
-
#### distinct(fieldName: string): Array Returns a distinct set of objects of a specific class.
-
#### endGroup(): RealmQuery End grouping of conditions ("right parenthesis") which was opened by a call to beginGroup()
-
#### endsWith(fieldName: string, value: string, casing?: boolean): RealmQuery Condition that the value of field ends with the specified string
-
#### equalTo(fieldName: string, value: string|number|boolean|date): RealmQuery Equal-to comparison
-
#### findAll(): ReamResults Finds all objects that fulfill the query conditions
-
#### findFirst(): Object
Finds the first object that fulfills the query conditions
-
#### greaterThan(fieldName: string, value: number|date): RealmQuery Greater-than comparison
-
#### greaterThanOrEqualTo(fieldName: string, value: number|date): RealmQuery greater-than-or-equal-to comparison
-
#### in(fieldName: string, values: string|number[]): RealmQuery In comparison
-
#### lessThan(fieldName: string, value: number|date): RealmQuery Less-than comparison
-
#### lessThanOrEqualTo(fieldName: string, value: number|date): RealmQuery Less-than-or-equal-to comparison
-
#### max(fieldName: string): Object Finds the maximum value of a field
-
#### min(fieldName: string): Object Finds the miniimum value of a field
-
#### not(): RealmQuery Negate condition
-
#### notEqualTo(fieldName: string, value: string|number|boolean|date): RealmQuery Not-equal-to comparison
-
#### and(): RealmQuery AND logic operator. Use in group
-
#### or(): RealmQuery OR logic operator. Use in group
let results = RealmQuery -
#### sum(): number Calculates the sum of a given field
-
#### sort(fieldName: string, order?: 'ASC' | 'DESC'): RealmQuery Set sorted into realm.objects
-
#### join(query: RealmQuery): RealmQuery Join queries
let query1 = RealmQuerylet query2 = RealmQuery;query1;query1toString = id == 1001 OR id == 1002 AND age > 25 -
#### where(objects?: RealmResults): RealmQuery Create new query
-
#### create(objects?: RealmResults): RealmQuery Create new query. Alias of where