pg-extra v3.0.0 provides helpful extensions and helpers for node-postgres (pg) without mutating the pg module. It adds a `pg.extra` namespace with extended Pool and Client classes that include convenient methods like `many`, `one`, `withTransaction`, `stream`, and `prepared` statement support. It also includes `sql` and `_raw` template literal tags to enforce parameterized queries and prevent SQL injection. Requires Node 8+ and pg 7.3+. Release cadence is low; stable, maintained project with no recent updates.
npm install pg-extraNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic usage: import extend, sql, _raw; extend pg; create pool; use many/one/withTransaction methods with template tags.
Upgrade Node to 8+ and pg to 7.3+.
Always use sql`...` for parameterized queries or _raw`...` for unsafe interpolation.
Prefersql`...` over _raw`...`. If you must use _raw, validate/sanitize inputs.
Call extend only once per pg instance to avoid multiple wrapping.
Use `const stream = await pool.stream(...)`
Use unique names for prepared statements, or avoid reusing names across queries.
Wrap the query with sql`...` or _raw`...` accordingly.
Call `const pg = extend(require('pg'))` and then use `new pg.extra.Pool(...)`.Add `import { sql } from 'pg-extra'` or `const { sql } = require('pg-extra')`.Run `npm install pg-extra` (and ensure pg is installed as a peer dependency).