Complex filtering expressions
This section describes the functionality of the utility class FilterExpressionUtils
, that provides a set of methods and utilities for building complex filtering expressions used in OntimizeWeb.
Filtering expression
A filtering expression is an object that defines an operation between two operands. The interface Expression
contains the basic structure of a filtering expression. The second operand may be omitted in some expressions, for example, filtering with a NULL value.
The filtering expression structure is the following;
{
/** The left operand. */
lop: string | Expression
/** The operator. */
op: string
/** The right operand. */
rop?: string | Expression
}
Operators
OntimizeWeb defines a set of operators used as the op
parametter of Expression
for building filtering expressions. This operators cover most important operations defined by every database management system and they are the following:
Operators | |
---|---|
AND | TRUE if both logical expressions are TRUE |
EQUAL | equal to a value |
LESS | less than a value |
LESS EQUAL | less than or equal to a value |
LIKE | TRUE if the operand matches a pattern |
MORE | more than a value |
MORE EQUAL | more than or equal to a value |
NOT EQUAL | not equal to a value |
NOT LIKE | TRUE if the operand not matches a pattern |
NULL | is NULL |
NOT NULL | is not NULL |
OR | TRUE if either logical expression is TRUE |
IN | TRUE if the operand is contained in the provided values |
All this operator are defined statically in FilterExpressionUtils
class with the operator prefix OP_
(OP_AND
, OP_EQUAL
, etc.).
Filter building methods
OntimizeWeb defines a set of methods for building filtering expressions automatically. This methods are the following:
buildArrayExpressionLike | |
---|---|
Builds an | |
Parameters | |
keys any[] |
the keys |
value any |
the value |
Returns | |
|
the |
buildExpressionEquals | |
---|---|
Builds an | |
Parameters | |
key string |
the key |
value any |
the value |
Returns | |
|
the |
buildExpressionIsNotNull | |
---|---|
Builds an | |
Parameters | |
key string |
the key |
Returns | |
|
the |
buildExpressionIsNull | |
---|---|
Builds an | |
Parameters | |
key string |
the key |
Returns | |
|
the |
buildExpressionLess | |
---|---|
Builds an | |
Parameters | |
key string |
the key |
value any |
the value |
Returns | |
|
the |
buildExpressionLessEqual | |
---|---|
Builds an | |
Parameters | |
key string |
the key |
value any |
the value |
Returns | |
|
the |
buildExpressionLike | |
---|---|
Builds an | |
Parameters | |
key string |
the key |
value any |
the value |
Returns | |
|
the |
buildExpressionLikeEnd | |
---|---|
Builds an | |
Parameters | |
key string |
the key |
value any |
the value |
Returns | |
|
the |
buildExpressionLikeStart | |
---|---|
Builds an | |
Parameters | |
key string |
the key |
value any |
the value |
Returns | |
|
the |
buildExpressionMore | |
---|---|
Builds an | |
Parameters | |
key string |
the key |
value any |
the value |
Returns | |
|
the |
buildExpressionMoreEqual | |
---|---|
Builds an | |
Parameters | |
key string |
the key |
value any |
the value |
Returns | |
|
the |
buildExpressionNotEquals | |
---|---|
Builds an | |
Parameters | |
key string |
the key |
value any |
the value |
Returns | |
|
the |
buildExpressionNotLike | |
---|---|
Builds an | |
Parameters | |
key string |
the key |
value any |
the value |
Returns | |
|
the |
buildExpressionNullAndValue | |
---|---|
Builds an | |
Parameters | |
key string |
the key |
value any |
the value |
Returns | |
|
the |
buildExpressionIn | |
---|---|
Builds an | |
Parameters | |
key string |
the key |
values any |
the values |
Returns | |
|
the |
Utility methods
OntimizeWeb also defines a set of utility methos to help you building complex filtering expressions. This methods are the following:
buildBasicExpression | |
---|---|
Builds a | |
Parameters | |
exp
|
the filtering expression |
Returns | |
|
the basic expression |
buildComplexExpression | |
---|---|
Builds a complex | |
Parameters | |
expr1
|
the first filtering expression to join |
expr2
|
the second filtering expression to join |
op string |
the joining operator |
Returns | |
|
the complex filtering expression |
buildExpressionFromObject | |
---|---|
Builds an | |
Parameters | |
obj any |
the object |
Returns | |
|
the |
buildFilterExpression | |
---|---|
Builds an | |
Parameters | |
exp
|
the filtering expression |
Returns | |
|
the |
instanceofBasicExpression | |
---|---|
Evaluates if the the expression provided is an instance of | |
Parameters | |
exp
|
the filtering expression |
Returns | |
boolean |
|
instanceofExpression | |
---|---|
Evaluates if an expresion is instance of | |
Parameters | |
exp any |
the expression to evaluate |
Returns | |
boolean |
|
instanceofFilterExpression | |
---|---|
Evaluates if an expresion is instance of | |
Parameters | |
exp any |
the expression to evaluate |
Returns | |
boolean |
|
Examples
The following example shows how to buid a Basic expression for querying a table using the FilterExpressionUtils
class. The expressions passed to the method buildBasicExpression
or buildFilterExpression
can be as complex as you need, in this case it is a simple like expression.
const filterExpr = FilterExpressionUtils.buildExpressionLike('EMPLOYEENAME', 'Caroline');
const basicExpr = FilterExpressionUtils.buildBasicExpression(filterExpr);
this.table.queryData(basicExpr);
The *filter sent to the backend results like the following:
"filter": {
"@basic_expression": {
"lop": "EMPLOYEENAME",
"op": "LIKE",
"rop": "%Caroline%"
}
}
It is possible to include additional filters that doesn’t belong to the Basic expression:
const filterExpr = FilterExpressionUtils.buildExpressionLike('EMPLOYEENAME', 'Caroline');
const basicExpr = FilterExpressionUtils.buildBasicExpression(filterExpr);
basicExpr['EMPLOYEETYPEID'] = 1;
this.table.queryData(basicExpr);
"filter": {
"@basic_expression": {
"lop": "EMPLOYEENAME",
"op": "LIKE",
"rop": "%Caroline%"
},
"EMPLOYEETYPEID": 1
}