express-parse-query-sequelize
v0.0.8
Published
[Express.js](https://expressjs.com) middleware used to parse http query to [Sequelize.js](https://sequelize.org).
Downloads
22
Maintainers
Readme
Express.js Parse Query To Sequelize.js
Express.js middleware used to parse http query to Sequelize.js.
It uses npm, TypeScript compiler, Jest, ESLint, Prettier, husky, pinst, commitlint. The production files include ES Modules and TypeScript declaration files.
Installation
npm install express-parse-query-sequelize
Usage
Server
import parserQueryMiddleware from "express-parse-query-sequelize";
app.use(parserQueryMiddleware);
// req.queryParsed contains a content of req.query parsed to sequelize
app.get("/user", (req: Request, res: Response) => {
UserModel.findAndCountAll(req.queryParsed)
.then((users) => {
res.status(200).json(users);
})
.catch((err: Error) => res.status(500).json(err));
});
Where
// Where name equals "john" and email equals "[email protected]"
?eq=name:john,email:[email protected]
// Where name is not equals "john"
?!eq=name:john
// Where id greater than "1"
?gt=id:1
// Where id less than "10"
?lt=id:10
// Where name like "%john%doe%"
?like=name:*john*doe*
// Where id equals "1" and name like "john"
?and[eq]=id:1&and[like]=name:john
// Where id equals "1" or name like "john"
?or[eq]=id:1&and[like]=name:john
Sorting
// Sort by id in ascending order
?sort_by=id:asc
// Sort by id in descending order
?sort_by=id:desc
// Sort by id in descending order and name in ascending order
?sort_by=id:desc,name:asc
Grouping
// Group by
?group_by=id,name
Fields
?fields=id,name,email
Operators
gt -----------> greater than
gte ----------> greater or equals than
lt -----------> less than
lte ----------> less than or equals
eq -----------> equals
!eq ----------> not equals
like ---------> like
!like --------> not like
between ------> between
!between -----> not between
in -----------> in
!in ----------> not in
and[op] ------> and operator
or[op] -------> or operator
Development
Install dependencies with npm
npm i
Note: make necessary changes in package.json the version of the package.
Test
Test your code with Jest framework:
npm run test
Note: this package uses husky, pinst and commitlint to automatically execute test and lint commit message before every commit.
Build
Build production (distribution) files in your dist folder:
npm run build
It generates ES Modules (in dist/ folder), as well as TypeScript declaration files (in dist/types folder).
publish
Publish the library on the npm:
npm run publishnpm