Registry / database / pg-cr-layer

pg-cr-layer

JSON →
library2.0.26jsnpmunverified

pg-cr-layer (v2.0.26) is a lightweight PostgreSQL interface layer that wraps the popular pg library with ES2015 promises and provides a simplified API for common database operations like queries, transactions, and stored procedures. It is designed to be compatible with mssql-cr-layer for easy switching between PostgreSQL and MSSQL. The package offers a pool configuration and parameterized queries with positional ($1, $2) and named (@param) placeholders, though it has not been updated since 2019 and lacks TypeScript definitions.

npm install pg-cr-layer
INSTALL
IMPORT
SIG · PG-CR-LAYER
P
pg-cr-layer
databasejavascriptv2.0.26
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.

PgCrLayer
const PgCrLayer = require('pg-cr-layer')
import PgCrLayer from 'pg-cr-layer'
The package does not ship ES modules; use CommonJS require. No default export.
constructor
new PgCrLayer(config)
new PgCrLayer() with no config or with invalid pool options
Config object follows pg.Pool config shape. Pool sub-object is optional.
execute
layer.execute(sql, params, options)
layer.execute(sql, params) without considering transaction scope
Use {transaction: t} in options to run within a transaction.

Shows basic CRUD: connect, create table, insert with parameterized query, and close connection.

const PgCrLayer = require('pg-cr-layer'); const config = { user: process.env.PGUSER || 'me', password: process.env.PGPASSWORD || 'password', host: process.env.PGHOST || 'localhost', port: parseInt(process.env.PGPORT, 10) || 5432, database: process.env.PGDATABASE || 'test', pool: { max: 10, idleTimeoutMillis: 30000 } }; const layer = new PgCrLayer(config); async function main() { await layer.connect(); await layer.execute('CREATE TABLE IF NOT EXISTS items (id serial primary key, name text)'); const result = await layer.query('INSERT INTO items (name) VALUES ($1) RETURNING id', ['apple']); console.log('Inserted ID:', result[0].id); await layer.close(); } main().catch(err => console.error(err));
Debug
Known issues
deprecatedPackage is not actively maintained; last release in 2019.
fix
Consider using modern alternatives like pg-promise, slonik, or the pg library directly.
affects: all
gotchaParameterized queries with named parameters (@param) use mssql-compatible syntax, but may not be fully documented or tested.
fix
Prefer positional parameters ($1, $2) for stability.
affects: all
gotchaThe library does not support ES modules; must use CommonJS require.
fix
Use require() instead of import.
affects: all
gotchaThe query method returns an array of rows directly, not a result object. Errors are raw pg errors.
fix
Handle errors with try-catch; check for empty arrays.
affects: all
Errors
Common errors & fixes
TypeError: PgCrLayer is not a constructor
Incorrect import (ES module import on CommonJS package).
fix
Use const PgCrLayer = require('pg-cr-layer');
Error: pool is not a function
Invalid pool configuration passed to constructor.
fix
Ensure pool sub-object contains valid pg.Pool options like max and idleTimeoutMillis.
error: syntax error at or near "@"
Used named parameter (@param) without proper definition.
fix
Use positional parameters ($1, $2) instead or provide a type object like { param: { value: 1, type: 'integer' } }.
Upgrade
Version history
2.0.26latest on npm
Audit
Dependencies
pgrequiredRuntime dependency for PostgreSQL connection via node-postgres
Agent activity
5 hits · last 30 days
node
4
Resources
pg-cr-layer — npm install pg-cr-layer · libregistry