
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
sequelize-qb
Advanced tools
A reusable query builder wrapper for Sequelize with:
Sequelize QueryBuilder simplifies repetitive queries and boosts performance by:
totalViews
or totalPosts
npm install sequelize-query-builder
QueryBuilder requires a Redis client to enable caching.
const { createClient } = require("redis");
const QueryBuilder = require("sequelize-query-builder");
const redis = createClient({ url: "redis://127.0.0.1:6379" });
await redis.connect();
// Initialize globally
QueryBuilder.init(redis);
const QueryBuilder = require("sequelize-query-builder");
// Assume User is a Sequelize model
const qb = new QueryBuilder(User);
const users = await qb
.select(["id", "name", "totalViews"]) // totalViews is a virtual attribute
.findAll();
const activeUsers = await qb
.filter({ status: "active" })
.findAll();
const sortedUsers = await qb
.sort([["createdAt", "DESC"]])
.findAll();
const paginatedUsers = await qb
.paginate({ page: 2, pageSize: 5 })
.findAll();
const usersWithPosts = await qb
.include([
{ model: Post, attributes: ["id", "title"] },
{ model: View, attributes: ["page"] }
])
.findAll();
const cachedUsers = await qb
.cache(60) // cache results for 60 seconds
.findAll();
Cache uses namespace-based keys, automatically invalidated when QueryBuilder.invalidate()
is called.
// Invalidate cache for a model and related models
await QueryBuilder.invalidate("User", ["Post", "View"]);
const qb = new QueryBuilder(User);
const users = await qb
.select(["id", "name", "totalPosts", "totalViews"]) // virtual attributes
.filter({ status: "active" })
.include([{ model: Post, attributes: ["title"] }])
.sort([["createdAt", "DESC"]])
.paginate({ page: 1, pageSize: 10 })
.cache(120) // 2 minutes
.findAll();
console.log(users);
QueryBuilder Method | Sequelize Feature | Compatibility | Notes |
---|---|---|---|
.select([...]) | attributes | ✅ Fully | Works with real and virtual attributes (via sequelize.literal). |
.filter({...}) | where | ✅ Fully | Supports Sequelize operators (Op.gt, Op.or, etc.). |
.include([...]) | include | ✅ Fully | Supports associations, nested includes, through, required. |
.sort([...]) | order | ✅ Fully | Works with multiple columns and associations. |
.paginate({ page, pageSize }) | limit + offset | ✅ Fully | Sets limit and offset correctly. |
.cache(ttl) | n/a | ✅ Fully | External Redis caching, does not modify Sequelize functionality. |
.findAll(options) | findAll | ✅ Fully | Respects all QueryBuilder options, caching optional. |
.findOne(options) | findOne | ✅ Fully | Respects all QueryBuilder options, caching optional. |
.log(true/false) | n/a | ✅ Fully | Only console logging, no effect on Sequelize. |
.enableGlobalLogging(true/false) | n/a | ✅ Fully | Global console logging. |
.invalidate(modelName, relatedModels) | n/a | ✅ Fully | Invalidates cached read queries for models and related models. |
.create(data, options) | create | ⚠️ Partial | Not wrapped by default; must manually invalidate cache if used. |
.update(values, options) | update | ⚠️ Partial | Not wrapped; call QueryBuilder.invalidate() after updates. |
.destroy(options) | destroy | ⚠️ Partial | Not wrapped; call QueryBuilder.invalidate() after deletions. |
.scope(...) | Sequelize scopes | ⚠️ Partial | Can pass via options to findAll, QueryBuilder does not automatically handle scopes. |
.raw | findAll({ raw: true }) | ⚠️ Partial | Works if passed manually; virtual attributes may need adjustment. |
.aggregate | count , sum , max | ❌ Not supported | QueryBuilder focuses on findAll/findOne; aggregates must use Sequelize directly. |
Virtual attributes: define in your model as:
User.virtualAttributes = (sequelize) => ({
totalViews: sequelize.literal(`(SELECT COUNT(*) FROM Views v WHERE v.userId = User.id)`),
totalPosts: sequelize.literal(`(SELECT COUNT(*) FROM Posts p WHERE p.userId = User.id)`)
});
QueryBuilder.invalidate()
after writes if needed.QueryBuilder.enableGlobalLogging(true);
qb.log(true);
QueryBuilder makes Sequelize queries:
MIT License
FAQs
Reusable query builder for Sequelize with caching and virtual attributes
The npm package sequelize-qb receives a total of 14 weekly downloads. As such, sequelize-qb popularity was classified as not popular.
We found that sequelize-qb demonstrated a healthy version release cadence and project activity because the last version was released less than 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
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.