@isatech/express-sequelize-query-filter

0.0.3 • Public • Published

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

Option Acceptable Values Details
alwaysCreate
  • true (default)
  • false
Creates filter in request object whether there is or not filters in the request url. Where true, if there is no filters in the request url, then the created filter is an empty object ({}). When false, if there is no filters in the request url, then no filter object is created.

Auhtor

Naísses Zóia Lima

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @isatech/express-sequelize-query-filter

Weekly Downloads

14

Version

0.0.3

License

MIT

Unpacked Size

5.18 kB

Total Files

5

Last publish

Collaborators

  • naisses.lima