Registry / database / sql-compose

sql-compose

JSON →
library2.4.5jsnpmunverified

SQL Compose (v2.4.5) is a lightweight JavaScript library for building parameterized SQL queries using function composition and string interpolation. Released in 2019, it follows a semver cadence with infrequent updates. It differentiates from raw template literals and ORMs by offering safe interpolation via wrapper functions, automatic parameter numbering, and support for nested thunks. The library is ESM-only and provides TypeScript definitions. Alternatives like sql-template-strings or squel offer similar functionality but with different API designs.

npm install sql-compose
INSTALL
IMPORT
SIG · SQL-COMPOSE
S
sql-compose
databasejavascriptv2.4.5
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.

build
import { build } from 'sql-compose'
const { build } = require('sql-compose')
ESM-only since v2; CJS require will throw.
config
import { config } from 'sql-compose'
import config from 'sql-compose'
config is a named export, not default.
auto
import { auto } from 'sql-compose'
const { auto } = require('sql-compose')
auto is a named export; CJS require fails in ESM-only package.

Builds a parameterized SQL query with dynamic IN clause and nested thunk using auto wrapper.

import { build, config, auto } from 'sql-compose'; config.formatFn = x => `%(${x})s`; const autoQuery = (opts) => (w) => auto(w)` val > ${ opts.min_val } `; const query = (opts) => (w) => ` SELECT * FROM table WHERE id IN (${ opts.ids.map(w).join(',') }) AND val < ${ w(opts.max_val) } AND ${ w(autoQuery(opts)) } `; const opts = { ids: [1, 2, 3], max_val: 8, min_val: 5 }; const [sql, params] = build(query(opts)); console.log(sql, params);
Debug
Known issues
breakingpackage.json 'type' field set to 'module' in v2; CommonJS require() results in ERR_REQUIRE_ESM
fix
Use import statements instead of require().
affects: >=2.0.0
gotchaWrapper function must be called directly (e.g., w(value)), not used as a template tag
fix
Always invoke w(value) to interpolate a scalar; use auto(w) for tagged template literals.
affects: all
gotchaThe auto wrapper returns a string, not a function; cannot be used further as a wrapper
fix
Call auto(w)`...` directly; do not assign auto(w) to a variable and try to reuse it as a wrapper.
affects: all
deprecatedconfig.formatFn is a global mutable setting that affects all subsequent builds; deprecated in favor of per-query options
fix
Apply custom formatting via build() second argument if available, or avoid global config.
affects: >=2.4.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/sql-compose/index.js not supported.
Package is ESM-only since v2; using require() in CommonJS project.
fix
Switch to import syntax or change your project to ESM.
TypeError: w is not a function
Using auto(w) as a wrapper function instead of calling auto(w)`...` directly.
fix
Use auto(w)`...` as a tagged template literal, not w(...).
ReferenceError: Cannot access 'build' before initialization
Circular dependency or incorrect import order when mixing ESM and CJS.
fix
Ensure all imports are static and at the top of the file.
Upgrade
Version history
2.4.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
12
Meta
1
OpenAI (training)
1
Resources
sql-compose — npm install sql-compose · libregistry