npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sequelize-query-filter-builder

v1.0.4

Published

Flexible, type-safe filter builder for Sequelize and raw SQL queries with validation, coercion, and compound logic support.

Readme

sequelize-query-filter-builder

Flexible, secure, and type-safe filter builder for Sequelize and raw SQL queries.

Features

  • Validate and coerce filter objects for safe query building
  • Supports all major Sequelize operators (eq, ne, gt, gte, lt, lte, like, in, between, etc.)
  • Compound logic (and, or) for complex queries
  • Type casting for dates, numbers, booleans, strings
  • Build Sequelize where objects or raw SQL WHERE clauses with named parameters
  • Implicit AND: If you pass an array of filter objects, it is treated as an implicit AND condition

Installation

npm install sequelize-query-filter-builder

Usage (ES Modules)

1. Build a Sequelize WHERE clause

import { buildSequelizeWhere } from 'sequelize-query-filter-builder';

const filter = {
  field: 'status',
  operator: 'eq',
  value: 'active',
  type: 'string'
};

const whereClause = buildSequelizeWhere(filter);
// Use in Sequelize: Model.findAll({ where: whereClause });

2. Compound filters

import { buildSequelizeWhere } from 'sequelize-query-filter-builder';

const filter = {
  and: [
    { field: 'status', operator: 'eq', value: 'active', type: 'string' },
    {
      or: [
        { field: 'amount', operator: 'gt', value: 100, type: 'number' },
        { field: 'amount', operator: 'lt', value: 10, type: 'number' }
      ]
    }
  ]
};

const whereClause = buildSequelizeWhere(filter);

3. Implicit AND with array of filters

import { buildSequelizeWhere } from 'sequelize-query-filter-builder';

const filters = [
  { field: 'status', operator: 'eq', value: 'active', type: 'string' },
  { field: 'amount', operator: 'gt', value: 100, type: 'number' }
];

const whereClause = buildSequelizeWhere(filters);
// Equivalent to: { [Op.and]: [ ... ] }

4. Raw SQL WHERE clause (named params)

import { buildRawQueryFromFilter } from 'sequelize-query-filter-builder';

const filter = {
  field: 'created_at',
  operator: 'between',
  value: ['2023-01-01', '2023-01-31'],
  type: 'date'
};

const { where, params } = buildRawQueryFromFilter(filter);
// db.query(`SELECT * FROM table WHERE ${where}`, { replacements: params });

API

Filter Object

  • field: Column name (string)
  • operator: One of eq, ne, gt, gte, lt, lte, like, notLike, iLike, notILike, in, notIn, between, notBetween, is, not
  • value: Value to compare (type depends on type)
  • type: string, number, int, boolean, date

Compound logic:

  • and: Array of filter objects
  • or: Array of filter objects

Implicit AND:
Passing an array of filter objects is treated as an implicit AND condition.

Functions

  • buildSequelizeWhere(filter): Returns a Sequelize-compatible where object.
  • buildRawQueryFromFilter(filter): Returns { where, params } for raw SQL queries (named parameters).

JSDoc Support

This package uses JSDoc for inline documentation of its API.
You can generate HTML documentation by running:

npx jsdoc index.js

Or view type hints and documentation in supported editors.

Main exported functions are documented with JSDoc comments:

  • buildSequelizeWhere(filter)
  • buildRawQueryFromFilter(filter)
  • validateFilterObject(filter)
  • coerceValue(value, type)

Extending

Add new operators or types by updating the operator map and allowed types in the source.

Testing

Run tests with:

npm test

License

MIT