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 thanlte: Less than or equal togt: Greater thangte: Greater than or equal tobetween: Between two values (requires an array with two values)contains: Contains a value (case-insensitive)c: Alias forcontainscaseSensitiveContains: Contains a value (case-sensitive)csc: Alias forcaseSensitiveContainsne: Not equal toeq: Equal to: Equal to (default condition)neContains: Does not contain a value (case-insensitive)nec: Alias forneContainsin: In a list of valuesnin: Not in a list of values
filters(Object): The flat filter conditions.
- (Object): The ORM query object.
Error: Throws an error if thebetweenfilter 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);