Registry / database / psqlorm

psqlorm

JSON →
library9.6.9jsnpmunverified

psqlorm is a lightweight ORM for PostgreSQL built on top of the pg npm package. Current stable version is 9.6.9. It provides two model classes: Model (basic SQL generation and execution) and PostgreModel (with automatic table synchronization and foreign key support). Key differentiators: minimal learning curve, direct use of pg connection/pool, support for advanced queries (ILIKE, JOIN, transaction), and built-in data export/import. It has undergone multiple breaking changes (v5, v7, v8, v9) focusing on API consistency and feature enhancements. Suitable for small to medium projects that need ORM simplicity without the overhead of larger ORMs like Sequelize or TypeORM.

npm install psqlorm
INSTALL
IMPORT
SIG · PSQLORM
P
psqlorm
databasejavascriptv9.6.9
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.

default (class)
const psqlorm = require('psqlorm'); const pqorm = new psqlorm(pgdb);
import psqlorm from 'psqlorm'; // No default ES import; only CommonJS exports available
psqlorm exports a CommonJS class. Use require() or as default in ES modules that interoperate with CJS.
initORM
const { initORM } = require('psqlorm'); const pqorm = initORM(dbconfig);
const initORM = require('psqlorm').initORM; // Correct, but wrong if using import: import { initORM } from 'psqlorm'; // Fails due to CJS-only
initORM is a named export. Use destructuring with require(). Not available as ES module named export.
PgError (or internal)
try { ... } catch (err) { if (err.code === '23505') { ... } }
import { PgError } from 'psqlorm'; // No such export
psqlorm does not export custom error types; catch raw pg errors and check the 'code' property.

Shows initializing psqlorm with initORM, creating a model for 'users' table, and running a simple select query.

const { initORM } = require('psqlorm'); const pqorm = initORM({ host: process.env.PGHOST ?? 'localhost', user: process.env.PGUSER ?? 'postgres', database: process.env.PGDATABASE ?? 'test', password: process.env.PGPASSWORD ?? '', max: 10 }); async function main() { const result = await pqorm.model('users') .where({ name: 'Alice' }) .select(); console.log(result); } main().catch(console.error);
Debug
Known issues
breakingv8 removes fdelete, finsert, fupdate methods.
fix
Use regular delete(), insert(), update() calls. For foreign key operations, ensure PostgreModel with auto-sync enabled.
affects: >=8.0.0
breakingv7 introduces backwards-incompatible changes to interface and options.
fix
Review the v7 upgrade guide: option properties renamed, join syntax changed, transaction callback signature updated.
affects: >=7.0.0 <8.0.0
breakingv5 requires pg dependency automatically (earlier versions did not include pg).
fix
For v4.x you must install 'pg' separately. For v5+ pg is installed automatically, but ensure pg version compatibility.
affects: >=5.0.0
deprecatedModel.prototype.fdelete, finsert, fupdate are deprecated since v8.
fix
Use delete(), insert(), update() with explicit foreign key conditions.
affects: >=8.0.0
gotchaCommonJS only: psqlorm does not provide ES module exports.
fix
Use require() or use a bundler that can consume CommonJS. Do not attempt import statements with ES modules.
affects: >=0.0.0
gotchaThe '@' mark disables automatic value quoting; if misused can lead to SQL injection.
fix
Use '@' only when you need raw SQL fragments. For user input, always use parameterized queries with '?' placeholders.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'pg'
For psqlorm versions <5, pg is not installed automatically.
fix
npm install pg
psqlorm_1.default is not a constructor
Using ES module import (import psqlorm from 'psqlorm') on a CommonJS module.
fix
Use const psqlorm = require('psqlorm');
Cannot read property 'model' of undefined
initORM returned undefined because dbconfig was incomplete or connection failed.
fix
Check dbconfig (host, user, database, password) and ensure PostgreSQL server is running.
column "id" does not exist
Referencing a column that doesn't exist in the table.
fix
Verify table schema and column names.
Upgrade
Version history
9.6.9latest on npm
Audit
Dependencies
pgrequiredCore PostgreSQL client; psqlorm generates SQL and delegates execution to pg.
Agent activity
9 hits · last 30 days
node
8
Resources