{"id":43553,"library":"pg-extension","title":"pg-extension","description":"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.","status":"active","version":"0.3.8","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/core-ts/postgres","tags":["javascript","pg","pg-extension","postgres","postgresql","sql","typescript"],"install":[{"cmd":"npm install pg-extension","lang":"bash","label":"npm"},{"cmd":"yarn add pg-extension","lang":"bash","label":"yarn"},{"cmd":"pnpm add pg-extension","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Underlying PostgreSQL client driver","package":"pg","optional":false}],"imports":[{"note":"Named export; default export is not available.","wrong":"import createPool from 'pg-extension'","symbol":"createPool","correct":"import { createPool } from 'pg-extension'"},{"note":"ESM-only package; commonjs require won't work.","wrong":"const { query } = require('pg-extension')","symbol":"query","correct":"import { query } from 'pg-extension'"},{"note":"Export is lowercase 'sql' (tagged template literal). Capital 'SQL' is a common mistake.","wrong":"import { SQL } from 'pg-extension'","symbol":"sql","correct":"import { sql } from 'pg-extension'"}],"quickstart":{"code":"import { createPool, query, sql } from 'pg-extension';\n\nasync function main() {\n  const pool = createPool({\n    host: 'localhost',\n    port: 5432,\n    user: 'myuser',\n    password: process.env.PGPASSWORD ?? '',\n    database: 'mydb',\n  });\n\n  // Using tagged template literal\n  const result = await query(sql`SELECT * FROM users WHERE id = ${1}`);\n  console.log(result.rows);\n\n  // Manual query with parameters\n  const users = await query('SELECT name, email FROM users WHERE active = $1', [true]);\n  console.log(users.rows);\n\n  // Transaction\n  await pool.transaction(async (client) => {\n    await client.query(sql`UPDATE accounts SET balance = balance - 100 WHERE id = 1`);\n    await client.query(sql`UPDATE accounts SET balance = balance + 100 WHERE id = 2`);\n  });\n}\n\nmain().catch(console.error);\n","lang":"typescript","description":"Shows creating a pool, running queries with tagged template literals and parameters, and using transactions."},"warnings":[{"fix":"Use `import { createPool } from 'pg-extension'` and call `createPool({...})` instead of `new Pool({...})`.","message":"v0.3.0 changed the API for creating a pool from `Pool` constructor to `createPool` function. Old code using `new Pool()` breaks.","severity":"breaking","affected_versions":"<0.3.0"},{"fix":"Use manually constructed strings or aliases for dynamic identifiers. Never interpolate user input into identifiers.","message":"The `sql` tagged template literal does NOT support dynamic identifiers (table names, column names). Attempting to interpolate them will cause SQL injection or syntax errors.","severity":"gotcha","affected_versions":"all"},{"fix":"Check for null: `const count = result.rowCount ?? 0;`","message":"The `query` function returns `QueryResult` objects. Accessing `rows` directly is safe, but the `rowCount` property may be null for certain queries (e.g., `CREATE TABLE`).","severity":"gotcha","affected_versions":"all"},{"fix":"Replace `import { Pool } from 'pg-extension'` with `import { createPool } from 'pg-extension'`.","message":"The `Pool` class export is deprecated since v0.3.0 and may be removed in a future version. Use `createPool` instead.","severity":"deprecated","affected_versions":">=0.3.0"}],"env_vars":null,"search_vec":"'0.3.8':25 'api':33 'automat':44 'base':32 'built':16,60 'built-in':59 'client':14 'configur':42 'connect':45 'differenti':48 'direct':51 'ergonom':56 'extens':3,6,82 'first':12 'generic':68 'ideal':72 'infer':40 'interfac':57 'javascript':78 'librari':15 'lightweight':9 'minim':41 'node.js':74 'offer':53 'packag':23 'parameter':62 'pg':2,5,22,50,79,81 'pg-extens':1,4,80 'pool':46 'popular':21 'postgr':36,83 'postgresql':13,84 'project':75 'promis':31 'promise-bas':30 'provid':27 'queri':35,63 'result':70 'simpl':29 'sql':85 'stabl':26 'strong':38 'support':65 'top':18 'transact':64 'type':39,71 'typescript':11,67,77,86 'typescript-first':10 'use':76 'version':24","created_at":"2026-06-05T17:00:20.899804+00:00","updated_at":"2026-06-05T17:00:20.899804+00:00","problems":[{"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.","cause":"Package not installed or import path incorrect.","error":"Error: Cannot find module 'pg-extension'"},{"fix":"Use named import: `import { createPool } from 'pg-extension'`.","cause":"Trying to use default import (`import createPool from 'pg-extension'`) which does not exist.","error":"TypeError: createPool is not a function"},{"fix":"Add `\"type\": \"module\"` to package.json or rename file to `.mjs`. Alternatively, use dynamic import: `const { createPool } = await import('pg-extension')`.","cause":"Running CommonJS (require) environment without transpilation.","error":"Error: Cannot use import statement outside a module"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/core-ts/postgres#readme","github":"ssh://git@github.com/core-ts/postgres","docs":null,"changelog":null,"pypi":null,"npm":"pg-extension","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}