Registry / database / pg-helpers

pg-helpers

JSON →
library1.0.0jsnpmunverified

pg-helpers is a lightweight Node.js library (v1.0.0) providing utility functions for querying PostgreSQL databases. It wraps common query patterns such as select, insert, update, and delete, and offers simple connection management via a configuration object. The library is designed for small-to-medium projects that want a thin layer over raw SQL without a full ORM. It uses the 'pg' package as a peer dependency and is released infrequently. Compared to Knex or Prisma, it provides minimal abstraction and is best for developers who prefer writing SQL with some helper shortcuts.

npm install pg-helpers
INSTALL
IMPORT
SIG · PG-HELPERS
P
pg-helpers
databasejavascriptv1.0.0
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.

query
import { query } from 'pg-helpers'
const query = require('pg-helpers').query
Package is ESM-only; CJS require cannot be used directly.
select
import { select } from 'pg-helpers'
import select from 'pg-helpers'
Named export, not default. Use destructuring.
pgHelpers
import * as pgHelpers from 'pg-helpers'
Namespace import to access all helpers at once. Avoid mixing with named imports.

Shows how to set up a pg pool and use query, select, and insert helpers.

import { query, select, insert, update, del } from 'pg-helpers'; import pg from 'pg'; const pool = new pg.Pool({ user: process.env.PG_USER || 'postgres', database: process.env.PG_DATABASE || 'test', password: process.env.PG_PASSWORD || '', host: 'localhost', port: 5432, }); async function main() { await query(pool, 'CREATE TABLE IF NOT EXISTS users (id SERIAL PRIMARY KEY, name TEXT)'); await insert(pool, 'users', { name: 'Alice' }); const users = await select(pool, 'users', { name: 'Alice' }); console.log(users.rows); } main().catch(console.error);
Debug
Known issues
breakingPackage is ESM-only. It will not work with require() in CommonJS projects.
fix
Use import syntax or set { "type": "module" } in package.json.
affects: >=1.0.0
gotchaThe 'del' function conflicts with JavaScript's delete operator; may cause confusion.
fix
Use it as del() or alias it with a different name when importing.
affects: >=1.0.0
gotchaThe 'pg' package must be installed separately as a peer dependency; not bundled.
fix
Run 'npm install pg' in your project.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'pg-helpers'
Package not installed or not resolvable
fix
Run 'npm install pg-helpers pg'
TypeError: (0 , _pgHelpers.query) is not a function
CommonJS require incorrectly used for ESM package
fix
Use ES module import syntax: import { query } from 'pg-helpers'
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
pgrequiredPeer dependency for PostgreSQL client connectivity
Agent activity
4 hits · last 30 days
node
4
Resources
pg-helpers — npm install pg-helpers · libregistry