Registry / database / postgresorm

postgresorm

JSON →
library5.1.1jsnpmunverified

PostgresORM is a minimalistic ORM for PostgreSQL, version 5.1.1. It provides basic CRUD operations, pagination, transactions, and custom query support with parameterized queries. Designed for simplicity, it uses a connection pool and requires manual release of database contexts. The library has low activity and is not actively maintained. It differentiates by offering a lightweight alternative to full-featured ORMs like Sequelize or TypeORM, but lacks advanced features like migrations, model definitions, or TypeScript support.

npm install postgresorm
INSTALL
IMPORT
SIG · POSTGRESORM
P
postgresorm
databasejavascriptv5.1.1
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.

initializeDatabase
✓ const { initializeDatabase } = require('postgresorm');
✗ const initializeDatabase = require('postgresorm');
initializeDatabase is a named export, not a default one.
db
✓ const { db } = require('postgresorm');
✗ const db = require('postgresorm').db;
db is a function, so it must be invoked as db() to get the database context.
pool
✓ const { pool } = require('postgresorm');
✗ const pool = require('postgresorm').pool;
pool is the underlying pg.Pool instance, accessible as a named export.

Demonstrates initialization, CRUD operations, custom query, pagination, and manual client release with PostgresORM.

const { initializeDatabase, db, pool } = require('postgresorm'); const config = { connectionString: process.env.DATABASE_URL ?? 'postgres://username:password@localhost:5432/mydb', max: 10, idleTimeoutMillis: 30000, }; initializeDatabase(config); async function run() { const client = await pool.connect(); const database = db(client); try { // Create a record const newUser = await database.create('users', { name: 'Alice', email: 'alice@example.com' }); console.log('Created user:', newUser); // List records const users = await database.list('users'); console.log('All users:', users); // Custom query with parameters const result = await database.customQuery('SELECT * FROM users WHERE name = $1', ['Alice']); console.log('Custom query result:', result); // Update a record await database.update('users', { name: 'Alice' }, { name: 'Alice Updated' }); // Paginate const paginated = await database.paginate('users', { sortby: 'ASC', limit: 10, page: 1 }); console.log('Paginated users:', paginated); } finally { await database.release(); } } run().catch(console.error);
Debug
Known issues
gotchaDatabase context (db object) must be released after use to return the connection to the pool.
fix
Always call await db.release() after finishing operations, especially when using a manually acquired client from pool.connect().
affects: >=0.0.0
gotchainitializeDatabase must be called exactly once before any db or pool usage, otherwise connections may fail.
fix
Call initializeDatabase(config) at application startup.
affects: >=0.0.0
breakingIn version 2.0.0, the API changed from default export to named exports. Old code using 'const pg = require('postgresorm')' and 'pg.initializeDatabase()' may still work, but direct use of 'pool' and 'db' requires destructuring.
fix
Update imports to use named exports: const { initializeDatabase, pool, db } = require('postgresorm');
affects: >=2.0.0
deprecatedThe 'findone' and 'findonerandom' methods are poorly documented and may be removed in future versions.
fix
Use 'list' with conditions or customQuery instead.
affects: >=0.0.0
gotchaThe 'conditions' parameter in list, paginate, findone, etc. is not parameterized and may be prone to SQL injection if constructed with user input.
fix
Always use parameterized customQuery instead of constructing conditions strings.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: initializeDatabase is not a function
Using default import instead of named import for initializeDatabase.
fix
Use const { initializeDatabase } = require('postgresorm');
Error: Cannot read properties of undefined (reading 'query')
Calling db methods without acquiring a client or calling db() first.
fix
Ensure you call db() or db(client) before using CRUD methods.
Error: pool is not defined
Accessing pool before initializeDatabase() is called.
fix
Call initializeDatabase(config) at the start of your application.
Error: Client has already been released
Calling release() on a database context that has already been released.
fix
Check if the context is already released or use a try/finally block to release only once.
Upgrade
Version history
5.1.1latest on npm
Audit
Dependencies
pgrequiredPostgreSQL client driver used for database connections and pool management.
Agent activity
8 hits · last 30 days
node
6
Resources
postgresorm — npm install postgresorm · libregistry