Registry / database / sql-buddy

sql-buddy

JSON →
library1.0.8jsnpmunverified

A tiny, zero-dependency SQL query builder for Node.js that tracks parameter order and safely handles parameterized queries. Version 1.0.8 is stable, with infrequent releases. It supports PostgreSQL-style $1 placeholders by default and can be configured for other dialects (e.g., @ for MSSQL). Differentiators: minimalistic API, template literal integration, and automatic comma-separated multi-append for arrays. Ships TypeScript definitions. Ideal for small projects needing a lightweight query builder without an ORM.

npm install sql-buddy
INSTALL
IMPORT
SIG · SQL-BUDDY
S
sql-buddy
databasejavascriptv1.0.8
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.

SqlBuddy
import SqlBuddy from 'sql-buddy'
const SqlBuddy = require('sql-buddy')
Package is ESM-only. Default export is a factory function.
pgsql
import { pgsql } from 'sql-buddy'
import pgsql from 'sql-buddy'
pgsql is a named export, not a default export.
postgres
import { postgres } from 'sql-buddy'
const { postgres } = require('sql-buddy')
Alternative named export with same behavior as pgsql. ESM only.
mysql
import { mysql } from 'sql-buddy'
Named export for MySQL-style ? placeholders. Available since v1.0.0.

Shows template literal usage, append, multiAppend with comma separation, and output properties text/values.

import { pgsql } from 'sql-buddy'; const query = pgsql`SELECT * FROM users WHERE id = ${42}`; console.log(query.text); // 'SELECT * FROM users WHERE id = $1' console.log(query.values); // [42] // With append and custom values const q = pgsql().append('SELECT $1', ['hello']); console.log(q.text); // 'SELECT $1' console.log(q.values); // ['hello'] // Multi-append with comma separation const items = [{name: 'Alice'}, {name: 'Bob'}]; const multi = pgsql().append('INSERT INTO users (name) VALUES') .multiAppend(items, (sb, item) => sb(${item.name})); console.log(multi.text); // 'INSERT INTO users (name) VALUES ($1) , ($2)' console.log(multi.values); // ['Alice', 'Bob']
Debug
Known issues
breakingVersions >=1.0.0 are ESM-only. If you use require(), the import will fail.
fix
Use import syntax or dynamic import(). If using CommonJS, downgrade to 0.x or use dynamic import.
affects: >=1.0.0
gotchaTemplate literals do not automatically escape SQL identifiers. Only parameters are safely parameterized.
fix
Do not interpolate user input directly into SQL text; always use parameter placeholders (${value}).
affects: all
deprecatedThe 'postgres' and 'mysql' named exports are deprecated in favor of 'pgsql' and 'mysql' but still exported.
fix
Use 'pgsql' for PostgreSQL or 'mysql' for MySQL. Import from 'sql-buddy'.
affects: <1.0.0
gotchaThe .append() method overrides previous parameter numbering. Appending after a template literal may cause unexpected parameter indices.
fix
Build the query in a single chain or use consistent append order. Test parameter indices.
affects: all
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require() to import an ESM-only package.
fix
Use import syntax or set type:'module' in package.json.
TypeError: pgsql is not a function
Importing pgsql as default export instead of named export.
fix
import { pgsql } from 'sql-buddy'
SyntaxError: Unexpected template string
Using template literal without importing the package correctly, or mixing tagged template with .append() incorrectly.
fix
Ensure you have a valid SqlBuddy instance (e.g., pgsql) and use it as a tagged template.
Upgrade
Version history
1.0.8latest 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-buddy — npm install sql-buddy · libregistry