Registry / database / simple-sql-query-builder

simple-sql-query-builder

JSON →
library2.0.1jsnpmunverified

A minimal SQL query builder with TypeScript support. Version 2.0.1 provides a chainable API for generating parameterized SQL queries (SELECT, INSERT, UPDATE, DELETE). Lightweight, no dependencies, and targets both Node.js and React Native environments. Differentiated by its simplicity and lack of ORM features, suitable for small projects or when full control over SQL is needed.

npm install simple-sql-query-builder
INSTALL
IMPORT
SIG · SIMPLE-SQL-QUERY-B
S
simple-sql-query-builder
databasejavascriptv2.0.1
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.

QueryBuilder
import { QueryBuilder } from 'simple-sql-query-builder'
import QueryBuilder from 'simple-sql-query-builder'
The library exports a named export, not a default export. CommonJS users: const { QueryBuilder } = require('simple-sql-query-builder')
select
import { select } from 'simple-sql-query-builder'
const select = require('simple-sql-query-builder').select
Named import for the select function. Works with both ESM and CJS.
QueryBuilder types
import type { QueryBuilder, QueryResult } from 'simple-sql-query-builder'
import { QueryBuilder } from 'simple-sql-query-builder' // no type-only import
Use type-only imports for TypeScript to avoid runtime overhead if only using types.

Shows basic SELECT query building with parameterized WHERE clause and chaining.

import { select, QueryBuilder } from 'simple-sql-query-builder'; const query: QueryBuilder = select('id, name') .from('users') .where('age > ?', [21]) .orderBy('name ASC') .limit(10); console.log(query.sql); // SELECT id, name FROM users WHERE age > ? ORDER BY name ASC LIMIT 10 console.log(query.params); // [21]
Debug
Known issues
breakingVersion 2.0 replaces the old builder API (e.g., .and(), .or()) with a chainable where method using raw SQL fragments.
fix
Update code to use .where('column = ?', [value]) instead of .and('column = ?', [value]) or .where().and().
affects: <2.0.0
deprecatedThe method .raw() is deprecated and will be removed in v3. Use .custom() instead.
fix
Replace .raw(sql) with .custom(sql).
affects: >=2.0.0 <3.0.0
gotchaParameters in .where() must be passed as an array, even for a single parameter.
fix
Use .where('col = ?', [value]), not .where('col = ?', value).
affects: >=2.0.0
gotchaThe library does not escape identifiers (table/column names). Only values are parameterized.
fix
Sanitize identifiers manually or use a separate validation library.
affects: >=2.0.0
broken for securityEscape and quote
fix
Identifiers are not escaped; ensure you trust the source of table/column names.
affects: >=2.0.0
Errors
Common errors & fixes
TypeError: queryBuilder.select is not a function
Importing default export instead of named export.
fix
Use import { select } from 'simple-sql-query-builder' or import { QueryBuilder } from 'simple-sql-query-builder' and call new QueryBuilder().select(...).
SyntaxError: Unexpected token ?
Using .where() without an array for params, e.g., .where('col = ?', value).
fix
Wrap parameters in an array: .where('col = ?', [value]).
ReferenceError: require is not defined
Using CommonJS require in an ESM context (or vice versa).
fix
Use import for ESM: import { select } from 'simple-sql-query-builder'. For CJS, ensure compatible environment.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
6
Meta
1
Resources
simple-sql-query-builder — npm install simple-sql-query-builder · libregistry