0.0.8 • Published 4 years ago
express-parse-query-sequelize v0.0.8
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-sequelizeUsage
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 "john@doe.com"
?eq=name:john,email:john@doe.com
// 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:johnSorting
// 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:ascGrouping
// Group by
?group_by=id,nameFields
?fields=id,name,emailOperators
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 operatorDevelopment
Install dependencies with npm
npm iNote: make necessary changes in package.json the version of the package.
Test
Test your code with Jest framework:
npm run testNote: 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 buildIt 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