Registry / database / sql-filter-builder

sql-filter-builder

JSON →
library1.0.15jsnpmunverified

sql-filter-builder is a lightweight, type-safe SQL filter/query builder for Node.js and TypeScript (current version: 1.0.15). It provides a simple API to dynamically build parameterized SQL queries with filters, orders, and aggregations, preventing SQL injection. Built with zero dependencies and full TypeScript support, it works with any SQL stack (Sequelize, Postgres, MySQL, SQLite). Its release cadence is low; the package has only a few versions. Key differentiators include its minimal footprint, no runtime dependencies, and an expressive API similar to ORM query builders.

npm install sql-filter-builder
INSTALL
IMPORT
SIG · SQL-FILTER-BUILDER
S
sql-filter-builder
databasejavascriptv1.0.15
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

buildDataQuery
import { buildDataQuery } from 'sql-filter-builder'
const buildDataQuery = require('sql-filter-builder');
ESM-only; TypeScript types are included.
Filter
import { Filter } from 'sql-filter-builder'
TypeScript type for filter objects.
Operator
import { Operator } from 'sql-filter-builder'
Enum with values like Operator.Eq, Operator.Gt, etc.
Params
import { Params } from 'sql-filter-builder'
TypeScript type for the params object passed to buildDataQuery.

Builds a parameterized SQL query with a single equality filter and outputs the SQL string and bound values.

import { buildDataQuery, Operator } from 'sql-filter-builder'; const baseSql = 'SELECT colA, colB FROM tableX'; const params = { filters: [ { key: 'colC', operator: Operator.Eq, value: 'some-value' }, ], }; const [sql, values] = buildDataQuery(baseSql, params); console.log(sql); console.log(values);
Debug
Known issues
gotchaOperator enum values are strings like 'eq', not symbols. Ensure correct imports.
fix
Use Operator.Eq from the package instead of comparing with raw strings.
affects: >=1.0
gotchaThe buildDataQuery function expects a Params object with a 'filters' array. Missing or empty filters may cause unexpected behavior.
fix
Always provide a filters array (empty array allowed) in the params object.
affects: >=1.0
gotchaThe returned SQL uses named placeholders like :colC. Some database adapters require ? or $1. Check compatibility.
fix
Use the second returned object (values) as replacements for your query interface (e.g., Sequelize's replacements option).
affects: >=1.0
Errors
Common errors & fixes
Cannot find module 'sql-filter-builder'
Package not installed or not in node_modules.
fix
Run 'npm install sql-filter-builder' and ensure your import path is correct.
Invalid filter: must have key, operator, and value
Filter object missing required properties.
fix
Ensure each filter in the array includes key (string), operator (Operator enum), and value.
Operator is undefined
Operator enum not imported correctly.
fix
Use 'import { Operator } from 'sql-filter-builder'' instead of require or wrong import path.
Upgrade
Version history
1.0.15latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
12
Meta
2
OpenAI (training)
1
Resources
sql-filter-builder — npm install sql-filter-builder · libregistry