@isatech/express-sequelize-query-filter
v0.0.3
Published
Express middleware for parsing request query filter to sequelize format (options).
Downloads
36
Readme
Express Sequelize Query Filter
Express middleware for parsing request query filter to sequelize format (options).
Install
With NPM:
npm install @isatech/express-sequelize-query-filter
Usage
The middleware adds an object to express request named filter, that can be used by sequelize to filter a query, i.e., the options in sequelize's query.
The query filter in URL must be a serialized JSON of sequelize filter (option).
Example:
Consider a model Product in sequelize. An endpoint to fecth all the products should look like:
app.get('/products', async (req, res) => { return db.Product.findAll(); });
Using the filter, the endpoint should be writter as:
const sqFilter = require('@isatech/express-sequelize-query-filter');
app.get('/products', sqFilter(), async (req, res) => { return db.Product.findAll(req.filter); });
Available Options
Auhtor
Naísses Zóia Lima
License
MIT