Class: Filter

iotcs.enterprise.Filter()

new Filter()

Creates a Filter builder object. This class allows to easily formulate filter queries and convert straight to Json Queries.
Example
let f = new iotcs.enterprise.Filter();

f = f.and([
    f.eq("name","Andrew"),
    f.or([f.not(f.in("maritalStatus", ["MARRIED", "SINGLE"])),
          f.gte("children.count", 1)]),
    f.gt("salary.rank", 3),
    f.lte("salary.rank", 7),
    f.like("lastName", "G%")
]);

iotcs.log(f.stringify());
// '{"$and":[{"name":{"$eq":"Andrew"}},{"$or":[{"$not":{"maritalStatus":{"$in":["MARRIED","SINGLE"]}}},{"children.count":{"$gte":1}}]},{"salary.rank":{"$gt":3}},{"salary.rank":{"$lte":7}},{"lastName":{"$like":"G%"}}]}';

Methods

(static) and(args) → {iotcs.enterprise.Filter}

And operator.

Checks if all conditions are true.

This function takes either an array of iotcs.enterprise.Filter or an indefinit number of iotcs.enterprise.Filter.

Parameters:
Name Type Description
args Array.<iotcs.enterprise.Filter> | iotcs.enterprise.Filter an array or variable length argument list of filters to AND
Returns:
a new Filter expressing this operation
Type
iotcs.enterprise.Filter

(static) eq(field, value) → {iotcs.enterprise.Filter}

Equality operator

Note that if the value string does contain a %, then this operation is replaced by the like operation.

Parameters:
Name Type Description
field string the field name
value string | number the value to compare the field against. Values can only be simple types such as numbers or string.
Returns:
a new Filter expressing this operation
Type
iotcs.enterprise.Filter

(static) exists(field, state) → {iotcs.enterprise.Filter}

Exists operator.

Checks whether the field's value matches the given boolean state.

Parameters:
Name Type Description
field string the field name
state boolean the boolean to test field against
Returns:
a new Filter expressing this operation
Type
iotcs.enterprise.Filter

(static) gt(field, value) → {iotcs.enterprise.Filter}

Greater-than operator
Parameters:
Name Type Description
field string the field name
value number the value to compare the field against. Values can only be simple types such as numbers or string.
Returns:
a new Filter expressing this operation
Type
iotcs.enterprise.Filter

(static) gte(field, value) → {iotcs.enterprise.Filter}

Greater-than-or-equal operator
Parameters:
Name Type Description
field string the field name
value number the value to compare the field against. Values can only be simple types such as numbers or string.
Returns:
a new Filter expressing this operation
Type
iotcs.enterprise.Filter

(static) in(field, valuearray) → {iotcs.enterprise.Filter}

Is-in operator.

Checks whether the field's value is one of the proposed values.

Parameters:
Name Type Description
field string the field name
valuearray Array.<string> | Array.<number> an array of same typed values to test the field against. Values can only be simple types such as numbers or string.
Returns:
a new Filter expressing this operation
Type
iotcs.enterprise.Filter

(static) like(field, match) → {iotcs.enterprise.Filter}

Like operator.

Checks whether the field's value matches the search query. Use % in the match string as search jocker, e.g. "jo%".

Note that if the match string does not contain any %, then this operation is replaced by the eq operation.

Parameters:
Name Type Description
field string the field name
match string the pattern matching string to test field against
Returns:
a new Filter expressing this operation
Type
iotcs.enterprise.Filter

(static) lt(field, value) → {iotcs.enterprise.Filter}

Less-than operator
Parameters:
Name Type Description
field string the field name
value number the value to compare the field against. Values can only be simple types such as numbers or string.
Returns:
a new Filter expressing this operation
Type
iotcs.enterprise.Filter

(static) lte(field, value) → {iotcs.enterprise.Filter}

Less-than-or-equal operator
Parameters:
Name Type Description
field string the field name
value number the value to compare the field against. Values can only be simple types such as numbers or string.
Returns:
a new Filter expressing this operation
Type
iotcs.enterprise.Filter

(static) ne(field, value) → {iotcs.enterprise.Filter}

Not-equal operator
Parameters:
Name Type Description
field string the field name
value string | number the value to compare the field against. Values can only be simple types such as numbers or string.
Returns:
a new Filter expressing this operation
Type
iotcs.enterprise.Filter

(static) not(filter)

Not operator

Checks if the negative condition is true.

Parameters:
Name Type Description
filter iotcs.enterprise.Filter a filter to negate

(static) or(args) → {iotcs.enterprise.Filter}

Or operator.

Checks if at least one of the conditions is true.

This function takes either an array of iotcs.enterprise.Filter or an indefinit number of iotcs.enterprise.Filter.

Parameters:
Name Type Description
args Array.<iotcs.enterprise.Filter> | iotcs.enterprise.Filter an array or variable length argument list of filters to OR
Returns:
a new Filter expressing this operation
Type
iotcs.enterprise.Filter

(static) stringify()

Alias for toString.

(static) toJSON()

Converts this filter into a JSON object

(static) toString()

Returns a string containing a string-ified version of the current filter.

Home