A safe and composable SQL string builder for Postgres using template strings. Current stable version: 1.1.0. The library exposes a `sql` template tag and helper functions (`sql.ident`, `sql.raw`, `sql.join`) that produce `{ text, values }` objects compatible with the `pg` npm package. It prevents SQL injection by treating all interpolated values as parameters unless explicitly escaped via `sql.ident` or `sql.raw`. Unlike ORMs or raw query building, `pg-sql` keeps full control of SQL while ensuring safety and composability. It is released on an as-needed basis and ships TypeScript definitions.
npm install pg-sqlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates safe query building with template strings, identifiers, and execution with the pg client.
Avoid `sql.raw` unless you fully trust the input. Use `sql.ident` for identifiers and parameters for values.
Use `pg.query(sql\`...\`)` instead of trying to stringify the result.
Use `import { sql } from 'pg-sql'`.Always pass strings to `sql.ident` unless you intentionally need local identifiers.
Use `import { sql } from 'pg-sql'` instead of `import sql from 'pg-sql'`.Ensure you use `import { sql } from 'pg-sql'`.Pass the result directly to `pg.query()`; do not call `.toString()` or concatenate.
Ensure you use `sql` template tag directly: `pg.query(sql\`select...\`)`.
No dependency data recorded yet.