A User-Friendly JavaScript/TypeScript Query Builder for Spring Filter.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
Elevate your development experience with our straightforward Query Builder designed for use alongside Spring Filter. This lightweight tool boasts simplicity by being dependency-free and compatible with TypeScript and JavaScript projects.
-
Install the package using NPM:
npm install spring-filter-query-builder
-
Import the required functions from
spring-filter-query-builder
into your JavaScript/TypeScript file:import { sfAnd, sfEqual, sfGt, sfIsNull, sfLike, sfNot, sfOr } from 'spring-filter-query-builder';
-
Here's an example of how to use the library:
const filter = sfAnd([sfEqual('status', 'active'), sfGt('createdAt', '1-1-2000')]); console.log(filter.toString());
This will output the generated filter query.
Explore Further with Examples
For additional examples, feel free to visit our CodeSandbox demo page.
All classes have a toString method. So you can convert any Object of these classes to string easily.
The library exposes all methods that you will need to create a query:
sfAnd([ item, item, ... ])
- and's one or more expressionssfOr([ item, item ... ])
- or's one or more expressionssfNot(item)
- not's an expressionsfExists(item)
- exists expression
sfLike(selector, value)
- Like comparatorsfEqual(selector, value)
- Equal comparatorsfNotEqual(selector, value)
- Not equal comparatorsfGt(selector, value)
- Greater than comparatorsfGe(selector, value)
- Greater than or equal comparatorsfLt(selector, value)
- Less than comparatorsfLe(selector, value)
- Less than or equal comparatorsfIsNull(selector)
- Is null comparatorsfIsNotNull(selector)
- Is not null comparatorsfIsEmpty(selector)
- Is empty comparatorsfIsNotEmpty(selector)
- Is not empty comparatorsfIn(selector, [ value, value, ...])
- In comparatorsfNotIn(selector, [ value, value, ...])
- Not in comparator
sfAbsolute(selector)
- Absolute functionsfAverage(selector)
- Average functionsfCeiling(selector)
- Ceiling functionsfConcat(value, value, ...)
- Concat functionsfCount(selector)
- Count functionsfCountDistinct(selector)
- CountDistinct functionsfCurrentDate()
- CurrentDate functionsfCurrentTime()
- CurrentTime functionsfCurrentTimestamp()
- CurrentTimestamp functionsfMin(selector)
- Min functionsfMax(selector)
- Max functionsfSum(selector, selector, ...)
- Sum functionsfSize(selector)
- Size functionsfLength(selector)
- Length functionsfTrim(selector)
- Trim functionsfUpper(selector)
- Upper functionsfLower(selector)
- Lower functionsfCustomFunction(functionName, value, value, ...)
- Any other custom function
Extend any of our predefined abstract classes – Comparator, Function, and Operator – to effortlessly craft custom logic tailored to your needs.
For creating custom comparators, refer to test/custom-comparator.test.ts.
For custom functions, explore test/custom-function.test.ts.
For custom operators, explore test/custom-operator.test.ts.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request