boosterfilters
v1.0.0
Published
Sequalize filter DSL
Downloads
3
Readme
BoostFilters
BoostFilters is a JavaScript package that generates Sequelize filters from a provided dictionary. It supports a wide range of filter types, including full-text search, greater than, less than, equals, and more.
Installation
Install BoostFilters via npm:
npm install boostfilters
or via yarn:
yarn add boostfilters
Usage
First, import the generateFilterConditions function from the boostfilters package:
import { generateFilterConditions } from "boostfilters";
you can use it to build Sequelize queries:
const filters = {
"name.fulltext": "John Doe",
"age.greaterThan": 30,
"createdAt.range": ["2022-01-01", "2023-01-01"],
};
const sequelizeFilters = generateFilterConditions(filters);
// Use `sequelizeFilters` in your Sequelize queries
In this example, sequelizeFilters will be an object suitable for use in a Sequelize where clause.
Query Types The generateFilterConditions function supports a variety of query types:
The keys of the query object should be the name of the field you want to query on, followed by a period and the type of the query. Here's a brief overview of each type:
fieldName.fulltext
: Performs a "LIKE" search on fieldName. Matches any records where fieldName contains the provided value.fieldName.equals
: Matches any records where fieldName is exactly equal to the provided value.fieldName.greaterThan
: Matches any records where fieldName is greater than the provided value.fieldName.lessThan
: Matches any records where fieldName is less than the provided value.fieldName.range
: Matches any records where fieldName is within the provided range. The value for this query type should be an array with two elements: the start of the range and the end of the range.fieldName.between
: Matches any records where fieldName is between the two provided values.fieldName.lessThanOrEqual
: Matches any records where fieldName is less than or equal to the provided value.
fieldName.greaterThanOrEqual
: Matches any records where fieldName is greater than or equal to the provided value.
You can also query associated tables by using the name of the associated table as a prefix to the field name, separated by a period. For example, to query the name field on an associated users
table entries, you would use the key users.name.fulltext
.