Registry / database / pg-cli

pg-cli

JSON →
library2.0.1jsnpmunverified

pg-cli is a small library wrapping node-pg (pg) to provide a more user-friendly PostgreSQL client for Node.js. It offers callback, thunk, and promise API styles, supports multiple database connection pools, and enables single- and multi-database transactions. Version 2.0.1 is stable, with a release cadence of approximately one year. It differentiates from raw pg by providing simplified CRUD operations like select, insert, update, updateBatch, and JSONB support, reducing boilerplate for common PostgreSQL tasks.

npm install pg-cli
INSTALL
IMPORT
SIG · PG-CLI
P
pg-cli
databasejavascriptv2.0.1
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.

default
const pgHelper = require('pg-cli');
import pgHelper from 'pg-cli';
This package is CommonJS only; no ESM exports available.
jsonbSet
const { jsonbSet } = require('pg-cli');
import { jsonbSet } from 'pg-cli';
jsonbSet is a named property on the default export. Use destructuring from require.
initPool
pgHelper.initPool(pgConf);
pgHelper.initPool({ ... }); // but need to call after require
Must call after requiring; no default pool.
query
pgHelper.query('SELECT * FROM users WHERE id=$1', [1], (err, res) => {});
pgHelper.query('SELECT * FROM users', {}, callback); // missing second argument
Second argument must be an array of parameters (or empty array).
select
pgHelper.select('users', ['name','age'], {name:'admin'}, callback);
pgHelper.select('Users', [], {name:'admin'}, callback); // table name is case-sensitive
Table names are case-sensitive; use quotes in SQL if needed.

Initialize a PostgreSQL pool and run a simple SELECT query using pg-cli.

const pgHelper = require('pg-cli'); const pgConf = { user: 'postgres', database: 'test', password: '123456', host: 'localhost', port: 5432, max: 10, min: 4, idleTimeoutMillis: 30000 }; pgHelper.initPool(pgConf); pgHelper.select('User', ['name'], { name: 'admin' }, (err, reply) => { if (err) console.error(err); else console.log(reply.rows); });
Debug
Known issues
gotchaTable names are case-sensitive. If your table is named 'User', you must use exactly that case in queries.
fix
Ensure table names in select/insert/update match the database exactly.
affects: >=1.0.0
gotchaAll methods expect positional arguments; forgetting the empty array for projection in select will cause errors.
fix
Always pass an array (even empty) as second argument to select.
affects: >=1.0.0
deprecatedThe library uses callbacks as default. While promises are supported via thunk, no native promise or async/await is provided.
fix
Wrap callbacks in Promises manually or use a promisify utility.
affects: >=1.0.0
gotchajsonbSet must be destructured from the default export before use.
fix
Use const { jsonbSet } = require('pg-cli');
affects: >=2.0.0
gotchaupdateBatch requires a unique key ('id' by default) to match rows; using wrong field will update unintended rows.
fix
Always verify the matching column name matches the where condition exactly.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'pg'
Missing peer dependency 'pg'.
fix
Run 'npm install pg' in your project.
TypeError: pgHelper.initPool is not a function
Incorrect import or using ESM import syntax.
fix
Use 'const pgHelper = require("pg-cli");' instead of import.
Error: relation "users" does not exist
Table name case mismatch or wrong schema.
fix
Use exact table name as defined in database (e.g., 'User' vs 'users').
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies
pgrequiredunderlying PostgreSQL client library
Agent activity
2 hits · last 30 days
node
2
Resources
packagepg-cli
pg-cli — npm install pg-cli · libregistry