-
Notifications
You must be signed in to change notification settings - Fork 0
Filtering
Use the elegant SQL syntax you already know, to filter your data.
Default where. Retrieves all nodes that fit the condition.
Parameters:
- field: the field to filter by.
- operator: the operator of the filter.
- value: the value the field has to be equal.
var data = [
{
id: 1,
name: 'Isaac',
birthdate: '1643-01-04',
swag: 99,
study_fields: [ 'Gravity', 'Light', 'Motion' ],
hasPet: undefined
},
{
id: 2,
name: 'Michael',
year: '1791-09-22',
swag: 87,
study_fields: [ 'Electromagnetism', 'Electrochemistry' ],
hasPet: true
},
{
id: 3,
name: 'Erwin',
year: '1887-08-12',
swag: 93,
study_fields: [ 'Quantum Mechanics' ],
hasPet: null
},
];
var result = Vivaz( data ).where( 'id', '>', 2 ).get();
// [ { id: 3, name: 'Erwin', ... } ]
The operator can be omitted, passing only two arguments. Vivaz will set the operator to "=" automatically for you.
var result = Vivaz( data ).where( 'name', 'Isaac' ).get();
// [ { id: 1, name: 'Isaac', ... } ]
- '=': Equal to. Loose comparison.
- '===': Equal to. Strict comparison.
- '!=': Not Equal to. Loose comparison.
- '!==': Not Equal to. Strict comparison.
- '<': Smaller than.
- '<=': Smaller or equal than.
- '>': Bigger than.
- '>=': Bigger or equal than.
- '<>': Not equal to. Alias of '!='.
- .whereNot(): The opposite of .where().
- .orWhere(): Adds the where clause to the query builder with an 'OR' boolean.
- .orWhereNot(): The opposite of .orWhere().
Retrieves all nodes that fit the condition. The value passed as argument and the value found on data fields will be casted and compared following the rules of native Date object.
Parameters:
- field: the field to filter by.
- operator: the operator of the filter.
- value: the value the field has to be equal. It has to be a valid Date object.
var result = Vivaz( data ).whereDate( 'birthdate', '>=', '1700-01-01' ).get();
// [ { id: 2, name: 'Michael', ... }, { id: 3, name: 'Erwin', ... } ]
The operator can be omitted, passing only two arguments. Vivaz will set the operator to "=" automatically for you.
var result = Vivaz( data ).whereDate( 'birthdate', '1643-01-04' ).get();
// [ { id: 1, name: 'Isaac', ... } ]
- '=': Equal to. Loose comparison.
- '===': Equal to. Strict comparison.
- '!=': Not Equal to. Loose comparison.
- '!==': Not Equal to. Strict comparison.
- '<': Smaller than.
- '<=': Smaller or equal than.
- '>': Bigger than.
- '>=': Bigger or equal than.
- '<>': Not equal to. Alias of '!='.
- .whereNotDate(): The opposite of .whereDate().
- .orWhereDate(): Adds the whereDate clause to the query builder with an 'OR' boolean.
- .orWhereNotDate(): The opposite of .orWhereDate().
Retrieves all nodes where field value is an array and its count fit the condition.
Parameters:
- field: the field to filter by.
- operator: the operator of the filter.
- value: the value the field has to be equal. It has to be an array.
var result = Vivaz( data ).whereCount( 'study_fields', '>=', 2 ).get();
// [ { id: 1, name: 'Isaac', ... }, { id: 2, name: 'Michael', ... } ]
The operator can be omitted, passing only two arguments. Vivaz will set the operator to "=" automatically for you.
var result = Vivaz( data ).whereCount( 'study_fields', 1 ).get();
// [ { id: 3, name: 'Erwin', ... } ]
- '=': Equal to.
- '!=': Not Equal to.
- '<': Smaller than.
- '<=': Smaller or equal than.
- '>': Bigger than.
- '>=': Bigger or equal than.
- '<>': Not equal to. Alias of '!='.
- .whereNotCount(): The opposite of .whereCount().
- .orWhereCount(): Adds the whereCount clause to the query builder with an 'OR' boolean.
- .orWhereNotCount(): The opposite of .orWhereCount().
Retrieves all nodes where field value fit between two given values.
Parameters:
- field: the field to filter by.
- min: minimum value.
- max: maximum value.
var result = Vivaz( data ).whereBetween( 'swag', 90, 100 ).get();
// [ { id: 1, name: 'Isaac', ... }, { id: 3, name: 'Erwin', ... } ]
Note: Under the hood, this clause it's treated as '>=' and '<='.
- .whereNotBetween(): The opposite of .whereBetween().
- .orWhereBetween(): Adds the whereBetween clause to the query builder with an 'OR' boolean.
- .orWhereNotBetween(): The opposite of .orWhereBetween().
Retrieves all nodes where field value is in array of passed values as argument.
Parameters:
- field: the field to filter by.
- values: array of values.
var result = Vivaz( data ).whereIn( 'study_fields', [ 'Gravity', 'Quantum Mechanics' ] ).get();
// [ { id: 1, name: 'Isaac', ... }, { id: 3, name: 'Erwin', ... } ]
- .whereNotIn(): The opposite of .whereIn().
- .orWhereIn(): Adds the whereIn clause to the query builder with an 'OR' boolean.
- .orWhereNotIn(): The opposite of .orWhereIn().
Retrieves all nodes where field value matches the regular expression passed as argument.
Parameters:
- field: the field to filter by.
- expression: Valid regular expression. It can be a string too.
var result = Vivaz( data ).whereLike( 'name', /ael/ ).get();
// [ { id: 2, name: 'Michael', ... } ]
- .whereNotLike(): The opposite of .whereLike().
- .orWhereLike(): Adds the whereLike clause to the query builder with an 'OR' boolean.
- .orWhereNotLike(): The opposite of .orWhereLike().
Retrieves all nodes where field value is strictly NULL. This is an alias for where( 'hasPet', '===', null ).
Parameters:
- field: the field to filter by.
var result = Vivaz( data ).whereNull( 'hasPet' ).get();
// [ { id: 3, name: 'Erwin', ... } ]
- .whereNotNull(): The opposite of .whereNull().
- .orWhereNull(): Adds the whereNull clause to the query builder with an 'OR' boolean.
- .orWhereNotNull(): The opposite of .orWhereNull().
Retrieves all nodes where field value is strictly undefined. This is an alias for where( 'hasPet', '===', undefined ).
Parameters:
- field: the field to filter by.
var result = Vivaz( data ).whereUndefined( 'hasPet' ).get();
// [ { id: 1, name: 'Isaac', ... } ]
- .whereNotUndefined(): The opposite of .whereUndefined().
- .orWhereUndefined(): Adds the whereUndefined clause to the query builder with an 'OR' boolean.
- .orWhereNotUndefined(): The opposite of .orWhereUndefined().
Retrieves all nodes where field value is strictly true. This is an alias for where( 'hasPet', '===', true ).
Parameters:
- field: the field to filter by.
var result = Vivaz( data ).whereTrue( 'hasPet' ).get();
// [ { id: 2, name: 'Michael', ... } ]
- .whereNotTrue(): The opposite of .whereTrue().
- .orWhereTrue(): Adds the whereTrue clause to the query builder with an 'OR' boolean.
- .orWhereNotTrue(): The opposite of .orWhereTrue().
Retrieves all nodes where field value is strictly false. This is an alias for where( 'hasPet', '===', false ).
Parameters:
- field: the field to filter by.
var result = Vivaz( data ).whereFalse( 'hasPet' ).get();
// []
- .whereNotFalse(): The opposite of .whereFalse().
- .orWhereFalse(): Adds the whereFalse clause to the query builder with an 'OR' boolean.
- .orWhereNotFalse(): The opposite of .orWhereFalse().