
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
sequelize-query-handler
Advanced tools
Dynamically handling queries with sequelize can be a pain. This package provides you with a function to query your database as you wish
Dynamically handling queries with sequelize can be a pain. This package provides you with a function to query your database as you wish
| Method | Type | Return |
|---|---|---|
handleQuery | function | object |
In your request body, make a GET request like this:
{
"_query": {
"attributes": [
"id",
"email",
"username",
"birthdate",
"created_at"
],
"order": [
[
"created_at",
"desc"
]
],
"include": ["Post"],
},
"page": 2,
"pageSize": 10
}
Use page and pageSize together to paginate.
Use include keyword to include associated models.
Use where keyword to make where clause query.
Use order keyword to order items
for more, refer to Sequelize Model Querying - Basics
findAll method:// imports
const models = require("./models");
const { handleQuery } = require("sequelize-query-handler");
const getAll = async (req, res) => {
try {
await models.User.findAll(handleQuery(req)).then((users) =>
res.send(users)
);
} catch (err) {
console.log(err);
}
};
findOne method:// imports
const models = require("./models");
const { handleQuery } = require("sequelize-query-handler");
const getOne = async (req, res) => {
try {
await models.User.findOne(handleQuery(req)).then((user) => res.send(user));
} catch (err) {
console.log(err);
}
};
findByPk method:// imports
const models = require("./models");
const { handleQuery } = require("sequelize-query-handler");
const getById = async (req, res) => {
try {
await models.User.findByPk(1, handleQuery(req)).then((user) =>
res.send(user)
);
} catch (err) {
console.log(err);
}
};
with own query method:// imports
const models = require("./models");
const { handleQuery } = require("sequelize-query-handler");
const { Op } = require("sequelize");
const getById = async (req, res) => {
try {
const filters = handleQuery(req);
// adding where clause to fetch user with age >= 18
filters.where = {
...filters.where,
age: {
[Op.gte]: 18,
},
};
await models.User.findAll(filters).then((user) => res.send(user));
} catch (err) {
console.log(err);
}
};
FAQs
Dynamically handling queries with sequelize can be a pain. This package provides you with a function to query your database as you wish
We found that sequelize-query-handler demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.