Registry / database / postgres-bridge

postgres-bridge

JSON →
library1.14.0jsnpmunverified

A compatibility layer that wraps the faster, leaner 'postgres' library (the porsager/postgres) with the widely-adopted 'pg' API (node-postgres). Currently at version 1.14.0, the project is stable and actively maintained with regular releases. Key differentiator: enables adopting the performance benefits of 'postgres' without migrating from 'pg' — especially useful for existing projects using Slonik or other pg-dependent libraries. Known limitations include no implicit pooling, no callback interface, no environment variable config, and no processID support.

npm install postgres-bridge
INSTALL
IMPORT
SIG · POSTGRES-BRIDGE
P
postgres-bridge
databasejavascriptv1.14.0
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.

createPostgresBridge
import { createPostgresBridge } from 'postgres-bridge'
const createPostgresBridge = require('postgres-bridge').createPostgresBridge
The package is ESM-only and ships TypeScript definitions. Named import is required; there is no default export.
PostgresBridge
const pool = new PostgresBridge(configuration)
const pool = new postgres.Pool(configuration)
PostgresBridge is a class returned by createPostgresBridge(postgres). It mimics pg.Pool. You must pass the postgres library instance as argument.
SqlTag
import type { SqlTag } from 'postgres-bridge'
import { SqlTag } from 'postgres-bridge'
SqlTag is a TypeScript type only; do not use at runtime. Import with 'import type' or 'import { type SqlTag }'.

Creates a PostgreSQL pool using postgres-bridge, connecting to a local PG instance and running a parameterized query.

import postgres from 'postgres'; import { createPostgresBridge } from 'postgres-bridge'; const PostgresBridge = createPostgresBridge(postgres); const pool = new PostgresBridge({ host: process.env.PGHOST ?? 'localhost', port: Number(process.env.PGPORT) ?? 5432, user: process.env.PGUSER ?? 'postgres', password: process.env.PGPASSWORD ?? '', database: process.env.PGDATABASE ?? 'postgres', max: 20, idleTimeoutMillis: 30000, connectionTimeoutMillis: 2000, }); async function main() { const connection = await pool.connect(); try { const result = await connection.query('SELECT $1::text AS name', ['hello']); console.log(result.rows); } finally { connection.release(); } } main().catch(console.error);
Debug
Known issues
gotchaImplicit query pooling is not implemented: you must always use pool.connect() to get a client.
fix
Replace pool.query() with pool.connect() then connection.query() and release.
affects: >=0.0.0
gotchaCallback (CPS) interface is not implemented: only promises are supported.
fix
Use async/await or .then() instead of callbacks.
affects: >=0.0.0
gotchaEnvironment variable configuration (e.g., PGHOST) is not supported: you must explicitly pass configuration object.
fix
Read environment variables manually and pass them to the constructor.
affects: >=0.0.0
gotchaconnection.processID is not implemented and will be undefined.
fix
Do not rely on processID; handle undefined gracefully.
affects: >=0.0.0
gotchapool._pulseQueue is not implemented.
fix
Avoid accessing private pool properties.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: createPostgresBridge is not a function
Importing default instead of named export (e.g., import createPostgresBridge from 'postgres-bridge').
fix
import { createPostgresBridge } from 'postgres-bridge'
Error: createPostgresBridge expected a postgres instance as first argument
Calling createPostgresBridge() without passing the postgres library.
fix
const PostgresBridge = createPostgresBridge(postgres);
TypeError: pool.query is not a function
Implicit pooling not supported; use pool.connect() first.
fix
const client = await pool.connect(); const result = await client.query(...); client.release();
Upgrade
Version history
1.14.0latest on npm
Audit
Dependencies
postgresrequiredThe underlying fast PostgreSQL client that postgres-bridge wraps to provide pg-compatible API.
Agent activity
7 hits · last 30 days
node
6
Resources
postgres-bridge — npm install postgres-bridge · libregistry