Registry / database / node-pg-helper

node-pg-helper

JSON →
library1.0.5jsnpmunverified

A small wrapper around node-postgres providing simplified CRUD helper functions (insert, update, upsert, selectAllRows) for PostgreSQL. Version 1.0.5, released once, no active development observed on GitHub. It relies on the 'pg' Pool client, which must be configured and set via setClient(). Avoids raw SQL for basic operations but offers no query builder flexibility, migrations, or connection pooling of its own. Suitable for quick prototypes but not production-grade; alternatives like Knex, Slonik, or pg-promise are more feature-rich and maintained.

npm install node-pg-helper
INSTALL
IMPORT
SIG · NODE-PG-HELPER
N
node-pg-helper
databasejavascriptv1.0.5
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.

require('node-pg-helper') (default export as object)
const db = require('node-pg-helper');
import db from 'node-pg-helper';
This package is CommonJS-only (no ESM exports). Using ES import syntax will fail.
setClient
db.setClient(pool);
setClient(pool);
setClient is a method on the default export object, not a named export.
insert
await db.insert('users', { id: 100, firstname: 'john' });
await db.insert('users', { id: 100, firstname: 'john' }, {});
insert only accepts table name and data object; no third argument. Extra arguments are ignored.
upsert
await db.upsert('users', { id: 100, firstname: 'john' }, 'id');
await db.upsert('users', { id: 100, firstname: 'john' }, ['id']);
The third parameter must be a string (single conflict column), not an array.
update
await db.update('users', { lastname: 'snow' }, { id: 100 });
await db.update('users', { lastname: 'snow' }, { id: 100 }, { returning: true });
update does not support options like 'returning' – it only returns undefined.

Initializes a pg Pool, sets client with setClient(), performs insert, selectAllRows, upsert, and update operations.

const { Pool } = require('pg'); const db = require('node-pg-helper'); const pool = new Pool({ connectionString: process.env.DATABASE_URL ?? '', ssl: { rejectUnauthorized: false } }); db.setClient(pool); async function run() { await db.insert('users', { id: 1, firstname: 'Alice', lastname: 'Smith' }); const rows = await db.selectAllRows('users'); console.log(rows); await db.upsert('users', { id: 1, firstname: 'Alice', lastname: 'Jones' }, 'id'); await db.update('users', { lastname: 'Johnson' }, { id: 1 }); await db.selectAllRows('users').then(r => console.log(r)); } run().catch(console.error);
Debug
Known issues
gotcha`selectAllRows` returns all rows without limit; may cause memory issues on large tables.
fix
Use pg query directly with LIMIT and OFFSET if needed.
affects: <=1.0.5
gotchaMissing `setClient()` call before any operation causes a runtime error: Cannot read property 'query' of undefined.
fix
Always call db.setClient(pool) after creating the Pool.
affects: <=1.0.5
deprecatedThe package has no active maintenance; no updates since initial release.
fix
Consider migrating to a maintained alternative like pg-promise, knex, or slonik.
affects: >=0.0.0
breakingThe package does not support async/await natively (promises returned are from pg queries, but no error handling wrappers).
fix
Wrap calls in try-catch or use .catch().
affects: <=1.0.5
Errors
Common errors & fixes
TypeError: db.setClient is not a function
Importing incorrectly (e.g., using ES import syntax or destructuring).
fix
Use const db = require('node-pg-helper');
Cannot read property 'query' of undefined
setClient() not called before performing a database operation.
fix
Call db.setClient(pool) after creating the pool.
Error: insert requires an object
Passing a non-object as data (e.g., array or string) to insert/upsert/update.
fix
Ensure the data argument is a plain object with key-value pairs.
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies
pgrequiredRequired peer dependency; node-pg-helper wraps pg's Pool for SQL queries.
Agent activity
8 hits · last 30 days
node
6
Resources
node-pg-helper — npm install node-pg-helper · libregistry