The buildPrismaQuery
function builds a Prisma query based on flat filter conditions.
The buildMongooseQuery
function builds a Mongoose query based on flat filter conditions.
The buildTypeORMQuery
function builds a TypeORM query based on flat filter conditions.
The buildSequelizeQuery
function builds a Sequelize query based on flat filter conditions. Here you also need to provide Op
object from sequelize
.
This functions take an object of flat filter conditions and converts it into a ORM query object. The filter conditions are expected to be in the format of field_condition: value
, where field
is the name of the field to filter on and condition
is the type of filter to apply.
-
lt
: Less than -
lte
: Less than or equal to -
gt
: Greater than -
gte
: Greater than or equal to -
between
: Between two values (requires an array with two values) -
contains
: Contains a value (case-insensitive) -
c
: Alias forcontains
-
caseSensitiveContains
: Contains a value (case-sensitive) -
csc
: Alias forcaseSensitiveContains
-
ne
: Not equal to -
eq
: Equal to -
-
neContains
: Does not contain a value (case-insensitive) -
nec
: Alias forneContains
-
in
: In a list of values -
nin
: Not in a list of values
-
filters
(Object): The flat filter conditions.
- (Object): The ORM query object.
-
Error
: Throws an error if thebetween
filter does not receive an array with two values.
const filters = {
age_gt: 30,
name_contains: "John",
status_in: ["active", "pending"],
};
const query = buildPrismaQuery(filters);
console.log(query);