pg-query is a lightweight wrapper around node-postgres that reduces boilerplate for PostgreSQL queries. Version 0.11.0 is the latest stable release, though the package is in maintenance mode with no active development. Key differentiators: 3-argument callback (err, rows, result), promise support via .spread(), query.first helper for single-row results, and domain-aware error handling. It uses a random pooled client per query, so it is not suitable for transactions. The package has no external dependencies beyond node-postgres (pg) and is designed for simple query operations.
npm install pg-queryNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Initialize pg-query with connection string and run a simple SELECT query with callback.
For transactions, use node-postgres directly with a client from pg.Client.
Use standard promise .then() with destructuring: query(sql).then(([rows, result]) => ...) or switch to a more modern library like postgres.js.
For a single value, pass the value directly; for multiple values, pass an array.
Consider migrating to the newer pg package's built-in pool query or postgres.js.
Run 'npm install pg-query' in your project directory.
Use 'const query = require('pg-query');' (CJS). Do not use import or destructure.Ensure PostgreSQL is started and connection string is correct: query.connectionParameters = 'postgres://user:pass@host:port/db';