Registry / database / lapiz-postgres

lapiz-postgres

JSON →
library1.0.3-betajsnpmunverified

A lightweight, class-based query system for PostgreSQL using the pg library. Current stable version is 1.0.3-beta. It provides a structured approach to organize SQL queries as reusable classes with named queries for prepared statements, built-in error handling via safeRawCall, and utility helpers for common transformations. Key differentiators include a focus on type safety through JSDoc, a simple API with DB class for pool management and query execution, and a strong opinion on project structure.

npm install lapiz-postgres
INSTALL
IMPORT
SIG · LAPIZ-POSTGRES
L
lapiz-postgres
databasejavascriptv1.0.3-beta
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.

Query
const Query = require('lapiz-postgres/query')
import { Query } from 'lapiz-postgres/query'
Package uses CommonJS; named import not supported. ESM import may fail.
DB
const DB = require('lapiz-postgres/db')
import DB from 'lapiz-postgres/db'
CommonJS module; default import only via require.
IQuery
/** @import {IQuery} from 'lapiz-postgres/query' */
import { IQuery } from 'lapiz-postgres/query'
Package uses JSDoc imports for TypeScript type checking; not an exportable symbol.

Shows how to define a query class and execute it using DB with pool configuration.

const DB = require('lapiz-postgres/db'); const Query = require('lapiz-postgres/query'); class GetUserById extends Query { constructor() { super('get-user-by-id', 'SELECT id, name FROM users WHERE id = $1'); } async run(pool, input) { const result = await this.rawCall(pool, [input.id]); return result.rows[0] || null; } } const db = new DB({ db_host: process.env.DB_HOST || 'localhost', db_port: 5432, db_user: process.env.DB_USER || 'postgres', db_password: process.env.DB_PASSWORD || '', db_name: process.env.DB_NAME || 'test' }, new GetUserById()); db.exec('get-user-by-id', { id: 1 }).then(user => console.log(user));
Debug
Known issues
gotchaPackage uses CommonJS, not ESM. Using ES import syntax may fail unless your project is configured for mixed modules.
fix
Use require() and avoid ES import statements for this package.
affects: >=1.0.0
gotchaThe Query class uses JSDoc for type hints; TypeScript users must install @types/pg separately for Pool types.
fix
Run npm install -D @types/pg to get types for pg Pool and PoolClient.
affects: >=1.0.0
breakingThe DB constructor expects query instances as additional arguments, not an array. Passing an array will cause the script to crash.
fix
Pass individual query objects as separate arguments: new DB(config, query1, query2, ...)
affects: >=1.0.0
gotchaQueries are named; duplicate names overwrite previously registered queries. Ensure unique names across all query classes.
fix
Use descriptive and unique names for each query.
affects: >=1.0.0
gotchasafeRawCall returns an object with properties result, database_error, unexpected_error. Always check both error properties before using result.
fix
Destructure with defaults: const { result, database_error, unexpected_error } = await this.safeRawCall(pool, params);
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: DB is not a constructor
Importing DB incorrectly as named import or using wrong syntax.
fix
Use const DB = require('lapiz-postgres/db');
Error: query name already exists: <name>
Duplicate query name passed to DB constructor.
fix
Ensure each Query instance has a unique name in its super() call.
TypeError: pool.end is not a function
Using a pool client instead of pool object for exec.
fix
Ensure you pass a Pool instance (not PoolClient) to the DB constructor or .exec().
Upgrade
Version history
1.0.3-betalatest on npm
Audit
Dependencies
pgrequiredPeer dependency for PostgreSQL connection and pool management
Agent activity
10 hits · last 30 days
node
10
Resources
lapiz-postgres — npm install lapiz-postgres · libregistry