sql-pg is a PostgreSQL query builder and ORM-like library built on top of the `pg` driver. It allows complex queries using tagged template literals (`` sql`...` ``) that look like native SQL and are secure by design (parameterized queries). Provides simple data manipulation methods (insert, update, delete) and selection methods (any, many, one, oneOrNone) inspired by pg-promise. Current stable version is 10.4.1, released on GitHub. Release cadence is irregular, with a major version bump to 10.0.0 in early 2023. Key differentiators: uses ES modules or CommonJS, works with PostgreSQL only, has a small API surface, and supports custom tag helpers. Peer dependencies required: pg, debug, and dotenv-safe.
npm install sql-pgNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic initialization, insert, selection, tagged template query, and transaction usage.
Upgrade Node.js to v14 or later and pg to 8.7.1+.
Use `db.sql` after calling the factory function.
Remove any usage of `sql.migrate()` or migration-related config.
Pass `{ returning: 'user_id' }` as third argument to insert if your primary key is not 'id'.Use `db.one(...)` for exactly one row, `db.oneOrNone(...)` for zero or one row.
Correct: `const sql = require('sql-pg')()` with parentheses.Use identifiers with proper quoting: `db.sql`${db.sql.identifier('Users')}``Run `npm install pg` (and debug, dotenv-safe if needed).