Registry / database / jorm
library2.2.5jsnpmunverified

Simple ORM (Object-Relational Mapping) library for Node.js that connects to PostgreSQL databases. Version 2.2.5, actively maintained. Key features include an intuitive CRUD interface, automatic field/public field management, custom SQL expressions, support for database triggers, and alias-based joins for related entities. The ORM uses a configuration-driven approach where you define models with fields, default values, public visibility, computed fields, and hooks (before/after select, insert, update, delete). It supports custom validation, hashing, and auto-initialization with init functions. Compared to heavier ORMs like Sequelize or TypeORM, jorm is lightweight and focuses on simplicity and flexibility without sacrificing control over SQL.

npm install jorm
INSTALL
IMPORT
SIG · JORM
J
jorm
databasejavascriptv2.2.5
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.

jorm
const Jorm = require('jorm'); const dto = new Jorm(params, config);
import Jorm from 'jorm';
jorm is a CommonJS module; ESM import is not supported (no default export). Use require() to load the constructor.
jorm.User.create
const newUser = dto.User.create({name: 'John'});
const newUser = Jorm.User.create({name: 'John'});
After constructing a jorm instance (dto), you access models as properties: dto.User, dto.Post, etc. Do not call methods on the raw require'd module.
user.save
user.save(function(err, user) { if (err) throw err; });
await user.save();
save() is callback-based and does not return a promise. You must use callbacks or promisify manually (e.g., util.promisify).

Configures jorm with a PostgreSQL connection, defines a User model with fields, creates and saves a new user, and outputs the public fields.

const Jorm = require('jorm'); const params = { connectionString: process.env.DATABASE_URL || 'postgres://user:pass@localhost:5432/mydb' }; const config = { User: { table: 'user', fields: { id: { pk: true }, name: { public: true }, email: { public: true }, password: {} }, init: function() { // this refers to the new object this.password = this.password ? someHash(this.password) : ''; } } }; const dto = new Jorm(params, config); // Create a new user const newUser = dto.User.create({ name: 'Alice', email: 'alice@example.com', password: 'secret' }); // Save to database newUser.save(function(err, savedUser) { if (err) { console.error('Save error:', err); return; } console.log('Saved user:', savedUser.getPublic()); // getPublic() returns object with only public fields });
Debug
Known issues
gotchajorm uses callbacks (not Promises) for all async operations. Using async/await will not work without promisification.
fix
Wrap calls in a promise: const save = util.promisify(user.save.bind(user)); await save();
affects: >=2.0.0
gotchaThe 'init' function on a model config is called with 'this' bound to the new object. It runs before save and is synchronous.
fix
Use init to set computed or transformed values (e.g., hash password). Do not perform async operations inside init.
affects: >=2.0.0
gotchaThe 'public' field attribute controls visibility in getPublic(). If a field is not marked as public, it is omitted by default.
fix
To include a field in all getPublic() calls, set {public: true}. To include only in specific scopes, use {public: 'scopeName'}.
affects: >=2.0.0
gotchaWhen using { db: 'demand' } on a field, that field is not included in SELECT queries unless explicitly requested via params.demand.
fix
Pass {demand: ['fieldName']} in the query parameters to include demand-only fields.
affects: >=2.0.0
gotchaField aliases (alias) are used to differentiate joined tables. Without an alias, jorm may overwrite fields with the same name.
fix
Always set unique aliases for fields that reference foreign keys, e.g., {alias:'GeoCurrent'} for current_geo_id.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'jorm'
jorm is not installed or not in node_modules
fix
npm install jorm
TypeError: Jorm is not a constructor
Attempting to import jorm as default ES module, but it's a CommonJS module
fix
Use const Jorm = require('jorm'); instead of import.
TypeError: Cannot read properties of undefined (reading 'create')
Calling dto.User.create before constructing a jorm instance with config, or misnaming the model key
fix
Ensure you have created the instance: const dto = new Jorm(params, config); then use dto.User.create(...).
error: relation "user" does not exist
The database table specified in config is missing or incorrectly named
fix
Create the table in your database matching the model's table name, or adjust the config.table value.
Upgrade
Version history
2.2.5latest on npm
Audit
Dependencies
pgrequiredPostgreSQL client for database connection
Agent activity
4 hits · last 30 days
node
4
Resources
packagejorm
jorm — npm install jorm · libregistry