rsql-filter-builder
Version:
Implementation of RSQL filter builder for NodeJs
103 lines (60 loc) • 1.56 kB
Markdown
Rslq-filter is a library to build RSQL query string in typescript.
Install rsql filter builder
```
npm i rsql-filter-builder
```
```ts
import { RSQLFilter } from "rsql-filter-builder";
search() {
const filter: string = RSQLFilter.new().equals('name','jhon').and().lessThan('age', 50).value();
}
//nested operation
search() {
const filter: string = RSQLFilter.new().equals('name','jhon').and(
RSQLFilter.new().gratherTan('age', 10).or().lessTahn('age',50).value()
).value();
}
```
It is possibile to use a less verbose operator:
```ts
search() {
const filter: string = RSQLFilter.new()
.equals('name','jhon')
.andLessThan('age', 50)
.orLikeAll('lastName', 'Gle')
.value();
}
```
It is possibile to iterate a specific condition:
```ts
search() {
const valueSplit = value?.split(' ');
const filter = RSQLFilter.new()
.iterate({
valueList: valueSplit,
operation: userSearch,
operator:','
})
};
const userSearch = (val: any) => {
return RSQLFilter.new()
.equals('name','jhon')
.andLessThan('age', 50)
.orLikeAll('lastName', 'Gle')
.value();
};
```
```ts
export class Filter extends RSQLFilter {
//New operation
exist(prop: string, value: any) {
return this.operation(prop, value, '=ex=')
}
}
```