Registry / database / sql-concat

sql-concat

JSON →
library4.1.0jsnpmunverified

Immutable MySQL query builder that produces parameterized queries compatible with mysqljs/mysql. Current stable version 4.1.0 (2023-10-09), releases are infrequent but stable. Unlike Knex, it is lightweight and allows raw SQL literals within clauses, with automatic parameter extraction via template literals. Ships TypeScript definitions. The library is designed for composability: base queries can be extended with conditional clauses without mutation.

npm install sql-concat
INSTALL
IMPORT
SIG · SQL-CONCAT
S
sql-concat
databasejavascriptv4.1.0
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.

default
import q from 'sql-concat'
const q = require('sql-concat')
ESM-only. Default export is the main query builder function.
QueryBuilder
import type { QueryBuilder } from 'sql-concat'
TypeScript type for the builder instance. Not used at runtime.
template literal tag
q`SELECT ${column} FROM table`
q('SELECT ? FROM table', column)
Tagged template literals automatically extract parameters. Do not use string interpolation with ? placeholders.

Shows basic SELECT query building with WHERE clauses and parameterized values using the immutable builder.

import q from 'sql-concat'; const minAge = 21; const result = q .select('name, email') .from('users') .where('age', '>=', minAge) .where('active', true) .build(); console.log(result.sql); // SELECT name, email FROM users WHERE age >= ? AND active = ? console.log(result.values); // [21, true]
Debug
Known issues
breakingDropped support for Node <6 in version 2.x. Upgrade Node or pin to 1.x.
fix
Use Node >=6.
affects: >=2.0.0
gotchaString values are automatically escaped as ? placeholders. Do not manually escape user input.
fix
Always pass raw values (not pre-escaped) to the builder methods.
affects: >=1.0.0
gotchaThe builder is immutable. Methods return new instances; forgetting to assign the return value discards changes.
fix
Always chain or reassign: query = query.where(...)
affects: >=1.0.0
gotchaSubquery builders must use .build() to get the object; when passed as a table, the builder is automatically built.
fix
Pass a subquery builder directly (no .build()) when using .join() or .from().
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: q is not a function
Using require('sql-concat') which returns a default export object instead of the function.
fix
Use ES import: import q from 'sql-concat'
Cannot find module 'sql-concat'
Package not installed or used in a CommonJS environment without ESM support.
fix
Run npm install sql-concat and ensure your project is set up for ESM (e.g., "type": "module" in package.json).
Property 'values' does not exist on type 'QueryBuilder'
Trying to access .values without calling .build() first.
fix
Call .build() on the builder to get { sql, values }.
Expected 0 arguments, but got 1.
Passing a string directly to the default import; the default export is a tagged template function.
fix
Use tagged template literal: q`query string`
Upgrade
Version history
4.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
14
Meta
1
OpenAI (training)
1
Resources
sql-concat — npm install sql-concat · libregistry