Registry / database / ba-db-postgres

ba-db-postgres

JSON →
library6.0.0jsnpmunverified

Database client for Postgres SQL that simplifies common DB operations. Current stable version is 6.0.0. Provides a high-level wrapper around the pg library with built-in connection pooling, query building, and migration support. Designed for Node.js applications needing a streamlined Postgres interface without heavy ORM overhead. Published as an ESM-only package with TypeScript definitions included.

npm install ba-db-postgres
INSTALL
IMPORT
SIG · BA-DB-POSTGRES
B
ba-db-postgres
databasejavascriptv6.0.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.

Client
import { Client } from 'ba-db-postgres'
const Client = require('ba-db-postgres')
ESM-only since v6; CommonJS require will fail. TypeScript types included.
Pool
import { Pool } from 'ba-db-postgres'
import Pool from 'ba-db-postgres'
Pool is a named export, not default.
query
import { query } from 'ba-db-postgres'
Used for executing raw SQL queries.

Connects to PostgreSQL, creates a table, inserts a row with parameterized query, and selects all users.

import { Client } from 'ba-db-postgres'; const client = new Client({ connectionString: process.env.DATABASE_URL ?? 'postgres://localhost:5432/mydb' }); await client.connect(); // Create a table await client.query(` CREATE TABLE IF NOT EXISTS users ( id SERIAL PRIMARY KEY, name VARCHAR(100), email VARCHAR(100) UNIQUE ); `); // Insert a user const insertResult = await client.query( 'INSERT INTO users (name, email) VALUES ($1, $2) RETURNING *', ['Alice', 'alice@example.com'] ); console.log('Inserted:', insertResult.rows[0]); // Query users const selectResult = await client.query('SELECT * FROM users'); console.log('All users:', selectResult.rows); await client.end();
Debug
Known issues
breakingSwitched to ESM-only in v6. CommonJS require() will throw an error.
fix
Use import syntax and ensure your project is configured for ES modules.
affects: >=6.0.0
breakingAPI changed: Client constructor now requires connectionString or config object. Removed support for environment variable auto-detection.
fix
Pass explicit connection string or config object when creating a Client or Pool instance.
affects: >=6.0.0
breakingUnified query method: #query now returns { rows, rowCount } instead of raw pg result. Access rows array directly.
fix
Update code to use result.rows instead of result.rows (previously result).
affects: >=6.0.0
deprecatedThe execute() method is deprecated. Use query() instead.
fix
Replace calls to execute() with query().
affects: >=5.5.0
deprecatedThe .raw property on query results is deprecated. Use .rows directly.
fix
Replace result.raw with result.rows.
affects: >=4.0.0
gotchaParameterized queries: Placeholders start at $1, not ?. Using ? will cause syntax errors.
fix
Use $1, $2, etc. for positional parameters.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
Using CommonJS require() with an ES module package in v6.
fix
Use import syntax or set type: module in package.json.
TypeError: client.connect is not a function
Importing the wrong export (e.g., default import instead of named import).
fix
Use import { Client } from 'ba-db-postgres'.
QueryResultError: expected rows but got undefined
Accessing result.rows before awaiting the query promise.
fix
Always await or .then() the query() call.
Upgrade
Version history
6.0.0latest on npm
Audit
Dependencies
pgrequiredUnderlying PostgreSQL driver used for all database communication
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
ba-db-postgres — npm install ba-db-postgres · libregistry