{"id":43574,"library":"pg-query","title":"pg-query","description":"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.","status":"maintenance","version":"0.11.0","language":"javascript","source_language":"en","source_url":"git://github.com/brianc/node-pg-query","tags":["javascript","postgres","PostgreSQL"],"install":[{"cmd":"npm install pg-query","lang":"bash","label":"npm"},{"cmd":"yarn add pg-query","lang":"bash","label":"yarn"},{"cmd":"pnpm add pg-query","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; pg-query uses whichever version of node-postgres is installed in the project.","package":"pg","optional":false}],"imports":[{"note":"CJS-only module; no ESM or default export. Use require.","wrong":"import query from 'pg-query';","symbol":"default","correct":"var query = require('pg-query');"},{"note":"Direct callable returned; not an object with query method.","wrong":"const { query } = require('pg-query');","symbol":"query","correct":"const query = require('pg-query');"},{"note":"query.first wraps non-array values in an array internally. You can pass a single value directly.","wrong":"query.first('SELECT * FROM users WHERE id = $1', [id], callback);","symbol":"query.first","correct":"query.first('SELECT * FROM users WHERE id = $1', id, callback);"}],"quickstart":{"code":"var query = require('pg-query');\n\nquery.connectionParameters = process.env.DATABASE_URL || 'postgres://user:password@localhost:5432/mydb';\n\nquery('SELECT NOW()', function(err, rows, result) {\n  if (err) {\n    console.error('Query failed:', err);\n    return;\n  }\n  console.log('Current time:', rows[0].now);\n});","lang":"javascript","description":"Initialize pg-query with connection string and run a simple SELECT query with callback."},"warnings":[{"fix":"For transactions, use node-postgres directly with a client from pg.Client.","message":"pg-query uses a random pooled client per query, so transactions (BEGIN/COMMIT) will not work correctly.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use standard promise .then() with destructuring: query(sql).then(([rows, result]) => ...) or switch to a more modern library like postgres.js.","message":"query.spread() returns a promise that resolves with an array [rows, result]; this is non-standard and may confuse users.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"For a single value, pass the value directly; for multiple values, pass an array.","message":"query.first() wraps non-array values in an array. Passing an array is passed as-is, which can lead to double-wrapping if you pass an array of single value.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Consider migrating to the newer pg package's built-in pool query or postgres.js.","message":"No breaking changes documented; package is stable but unmaintained.","severity":"breaking","affected_versions":"0.11.0"}],"env_vars":null,"search_vec":"'0.11.0':22 '3':41 'activ':37 'argument':42 'around':11 'awar':61 'beyond':85 'boilerpl':17 'callback':43 'client':69 'depend':84 'design':92 'develop':38 'differenti':40 'domain':60 'domain-awar':59 'err':44 'error':62 'extern':83 'handl':63 'helper':52 'javascript':97 'key':39 'latest':25 'lightweight':9 'mainten':33 'mode':34 'node':13,87 'node-postgr':12,86 'oper':96 'packag':30,80 'per':70 'pg':2,5,89 'pg-queri':1,4 'pool':68 'postgr':14,88,98 'postgresql':19,99 'promis':47 'queri':3,6,20,71,95 'query.first':51 'random':67 'reduc':16 'releas':27 'result':46,57 'row':45,56 'simpl':94 'singl':55 'single-row':54 'spread':50 'stabl':26 'suitabl':76 'support':48 'though':28 'transact':78 'use':65 'version':21 'via':49 'wrapper':10","created_at":"2026-06-05T17:00:27.026106+00:00","updated_at":"2026-06-05T17:00:27.026106+00:00","problems":[{"fix":"Run 'npm install pg-query' in your project directory.","cause":"The pg-query package is not installed or node_modules is missing.","error":"Error: Cannot find module 'pg-query'"},{"fix":"Use 'const query = require('pg-query');' (CJS). Do not use import or destructure.","cause":"Trying to import pg-query using ES module syntax or destructuring wrong.","error":"TypeError: query is not a function"},{"fix":"Ensure PostgreSQL is started and connection string is correct: query.connectionParameters = 'postgres://user:pass@host:port/db';","cause":"PostgreSQL server is not running or connection parameters are wrong.","error":"Error: connect ECONNREFUSED"}],"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/brianc/node-pg-query","github":"git://github.com/brianc/node-pg-query","docs":null,"changelog":null,"pypi":null,"npm":"pg-query","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}}