Registry / database / pg-batch-query

pg-batch-query

JSON →
library1.4.5jsnpmunverified

pg-batch-query v1.4.5 is a lightweight PostgreSQL batch query library that uses the Extended Query Protocol to triple query throughput by batching multiple parameter sets into a single parse-bind-execute sync cycle. It is a thin wrapper around the popular 'pg' driver, requiring Node 22+. Unlike naive Promise.all or individual queries, it sends multiple binds/exeutes over one connection without waiting for results until Sync. Ships TypeScript types. Infrequent releases, maintained by iamkhush. Differentiator: performance gains through wire protocol batching vs. sequential or concurrent pg queries.

npm install pg-batch-query
INSTALL
IMPORT
SIG · PG-BATCH-QUERY
P
pg-batch-query
databasejavascriptv1.4.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.

BatchQuery
import BatchQuery from 'pg-batch-query'
const { BatchQuery } = require('pg-batch-query')
Default export only; named export does not exist. CommonJS users must require the default: const BatchQuery = require('pg-batch-query').default or use the object spread.
BatchQuery
const BatchQuery = require('pg-batch-query').default
const BatchQuery = require('pg-batch-query')
In CommonJS, the default export is on the .default property. Using require directly returns the module, not the class.
BatchQuery<RowType>
const batch = new BatchQuery<User>({ name: 'q', text: '...', values: [['a'], ['b']] })
new BatchQuery<User>({ rows: [...] })
Type parameter is optional for typed rows. The constructor expects an object with 'text' and 'values' (array of arrays). 'name' is optional.

Batch insert three items using extended query protocol; prints inserted rows.

import pg from 'pg'; import BatchQuery from 'pg-batch-query'; const pool = new pg.Pool(); async function batchInsert() { const client = await pool.connect(); try { const batch = new BatchQuery({ name: 'insert_items', text: 'INSERT INTO items (name, value) VALUES ($1, $2) RETURNING *', values: [ ['apple', 100], ['banana', 200], ['cherry', 300] ] }); const results = await client.query(batch).execute(); for (const result of results) { console.log(`Inserted ${result.rowCount} rows`); for (const row of result.rows) { console.log(row); } } } finally { client.release(); } } batchInsert().catch(console.error);
Debug
Known issues
breakingRequires Node >= 22.0.0 due to engine constraints in package.json.
fix
Upgrade Node to 22 or later.
affects: >=1.4.5
gotchaBatchQuery instances are stateful and single-use. Calling execute() twice on the same instance throws an error.
fix
Create a new BatchQuery instance for each batch execution.
affects: >=1.0.0
gotchaRequires peer dependency pg. Must install 'pg' separately.
fix
Run 'npm install pg' or 'yarn add pg'.
affects: >=1.0.0
gotchaCommonJS require returns the module object, not the class directly. Must use .default.
fix
Use 'const BatchQuery = require('pg-batch-query').default'.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: require(...) is not a constructor
Using CommonJS require without accessing .default property.
fix
Use 'const BatchQuery = require('pg-batch-query').default'
BatchQuery is not a constructor
Importing as named export instead of default export.
fix
Use 'import BatchQuery from 'pg-batch-query'' (default import)
Error: execute() has already been called
Calling execute() more than once on the same BatchQuery instance.
fix
Create a new BatchQuery instance for each batch.
Upgrade
Version history
1.4.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
pg-batch-query — npm install pg-batch-query · libregistry