Installation
npm install --save @rsql/builder
yarn add @rsql/builder
API
builder.comparision(selector, operator, value): ComparisionNode
Creates new ComparisionNode
- can be used as a base for custom operator factory
builder.<operator>(selector, value): ComparisionNode
builder.eq(selector, value): ComparisionNode
builder.neq(selector, value): ComparisionNode
builder.le(selector, value): ComparisionNode
builder.lt(selector, value): ComparisionNode
builder.ge(selector, value): ComparisionNode
builder.gt(selector, value): ComparisionNode
Creates new ComparisionNode
with the predefined operator for single value.
builder.<operator>(selector, values): ComparisionNode
builder.in(selector, values): ComparisionNode
builder.out(selector, values): ComparisionNode
Creates new ComparisionNode
with the predefined operator for multiple values.
builder.<operator>(...expressions): LogicNode
builder.and(...expressions): LogicNode
builder.or(...expressions): LogicNode
Creates new LogicNode
with the predefined operator for one or more expressions.
builder.emit(ast): string
Emits RSQL string from the Abstract Syntax Tree. Same as emit
function from @rsql/emitter
package.
builder.parse(rsql): ExpressionNode
Parses RSQL string and returns Abstract Syntax Tree. Same as parse
function from @rsql/parser
package.
Example
import builder from "@rsql/builder";
function createDateRangeQuery(selector, from, to) {
return builder.emit(builder.and(builder.ge(selector, from.toISOString()), builder.le(selector, to.toISOString())));
}
console.log(createDateRangeQuery("createdAt", new Date("2019-07-10"), new Date("2020-04-29")));
License
MIT