1.1.2 • Published 4 years ago
odata-filter v1.1.2
oData Filter
Small filter library for working with immutable AST(abstract syntax trees) and queries
Installation
npm install odata-filterUsage
Compile a JSON-AST code that can be used later by a transformer:
import { Parse } from "odata-filter";
const code = `(user.username == "Ana") or (username == "Mari")`;
Parse(code).then(ast => {
console.log(ast); // { type: "...", ... }
}).catch(error => {
console.error(error);
});Compile a mysql where clause from a string using a transformer:
import { Parse } from "odata-filter";
import MySqlTransformer from "odata-filter-mysql";
const code = `(user.username == "Ana") or (username == "Ana")`;
Parse(code, {
transformer: new MySqlTransformer()
}).then(query => {
console.log(query); // (`user`.`username` == 'Ana') OR (`username` == 'Ana')
}).catch(error => {
console.error(error);
});Supported Functions
Parse(code, {
cache?: boolean,
transformer?: ITransformer
}): Promise<any>;ParseSync(code, {
cache?: boolean,
transformer?: ITransformer
}): any;Available Common Transformers
Functions Syntax
FUNCTION_NAME(arg1, arg2, ...)
LOWER(arg1)
concat(arg1, arg2)Supported Operators
| Name | Operator | Alias |
|---|---|---|
| Equals | == | |
| Not Equals | != | |
| Less than or equal | <= | |
| Greater Than or Equal | >= | |
| Less Than | < | |
| Greater Than | > | |
| Logical And | && | and |
| Logical Or | || | or |
| Contains | *= | |
| Contains Word | ~= | |
| Starts With | ^= | |
| Ends With | =$ | |
| Arithmetic Add | + | |
| Arithmetic Subtraction | - | |
| Arithmetic Multiplication | * | |
| Arithmetic Division | / |