Registry / database / pg-extension

pg-extension

JSON →
library0.3.8jsnpmunverified

pg-extension is a lightweight, TypeScript-first PostgreSQL client library built on top of the popular `pg` package. Version 0.3.8 (stable) provides a simple, promise-based API for querying Postgres with strong type inference, minimal configuration, and automatic connection pooling. It differentiates from `pg` directly by offering a more ergonomic interface with built-in parameterized queries, transaction support, and TypeScript generics for result types. Ideal for Node.js projects using TypeScript.

npm install pg-extension
INSTALL
IMPORT
SIG · PG-EXTENSION
P
pg-extension
databasejavascriptv0.3.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.

createPool
import { createPool } from 'pg-extension'
import createPool from 'pg-extension'
Named export; default export is not available.
query
import { query } from 'pg-extension'
const { query } = require('pg-extension')
ESM-only package; commonjs require won't work.
sql
import { sql } from 'pg-extension'
import { SQL } from 'pg-extension'
Export is lowercase 'sql' (tagged template literal). Capital 'SQL' is a common mistake.

Shows creating a pool, running queries with tagged template literals and parameters, and using transactions.

import { createPool, query, sql } from 'pg-extension'; async function main() { const pool = createPool({ host: 'localhost', port: 5432, user: 'myuser', password: process.env.PGPASSWORD ?? '', database: 'mydb', }); // Using tagged template literal const result = await query(sql`SELECT * FROM users WHERE id = ${1}`); console.log(result.rows); // Manual query with parameters const users = await query('SELECT name, email FROM users WHERE active = $1', [true]); console.log(users.rows); // Transaction await pool.transaction(async (client) => { await client.query(sql`UPDATE accounts SET balance = balance - 100 WHERE id = 1`); await client.query(sql`UPDATE accounts SET balance = balance + 100 WHERE id = 2`); }); } main().catch(console.error);
Debug
Known issues
breakingv0.3.0 changed the API for creating a pool from `Pool` constructor to `createPool` function. Old code using `new Pool()` breaks.
fix
Use `import { createPool } from 'pg-extension'` and call `createPool({...})` instead of `new Pool({...})`.
affects: <0.3.0
gotchaThe `sql` tagged template literal does NOT support dynamic identifiers (table names, column names). Attempting to interpolate them will cause SQL injection or syntax errors.
fix
Use manually constructed strings or aliases for dynamic identifiers. Never interpolate user input into identifiers.
affects: all
gotchaThe `query` function returns `QueryResult` objects. Accessing `rows` directly is safe, but the `rowCount` property may be null for certain queries (e.g., `CREATE TABLE`).
fix
Check for null: `const count = result.rowCount ?? 0;`
affects: all
deprecatedThe `Pool` class export is deprecated since v0.3.0 and may be removed in a future version. Use `createPool` instead.
fix
Replace `import { Pool } from 'pg-extension'` with `import { createPool } from 'pg-extension'`.
affects: >=0.3.0
Errors
Common errors & fixes
Error: Cannot find module 'pg-extension'
Package not installed or import path incorrect.
fix
Run `npm install pg-extension pg` (pg is a peer dependency). Ensure you are using ESM: `"type": "module"` in package.json or use `.mjs` extension.
TypeError: createPool is not a function
Trying to use default import (`import createPool from 'pg-extension'`) which does not exist.
fix
Use named import: `import { createPool } from 'pg-extension'`.
Error: Cannot use import statement outside a module
Running CommonJS (require) environment without transpilation.
fix
Add `"type": "module"` to package.json or rename file to `.mjs`. Alternatively, use dynamic import: `const { createPool } = await import('pg-extension')`.
Upgrade
Version history
0.3.8latest on npm
Audit
Dependencies
pgrequiredUnderlying PostgreSQL client driver
Agent activity
6 hits · last 30 days
node
6
Resources
pg-extension — npm install pg-extension · libregistry