Registry / database / xorm
library0.7.6jsnpmunverified

xorm is a Node.js ORM wrapper around Objection.js (v0.7.6) that adds conventions like automatic table naming (model class name), managed timestamps (createdAt/updatedAt), and soft delete support with methods like withTrashed/forceDelete. It requires knex (>=0.19.0 <1.0) as the SQL query builder and sm-utils. It is maintained by Smartprix, with moderate release cadence. Key differentiators vs. Objection: less boilerplate, built-in timestamp/soft-delete lifecycle hooks.

npm install xorm
INSTALL
IMPORT
SIG · XORM
X
xorm
databasejavascriptv0.7.6
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.

Model
import { Model } from 'xorm'
const { Model } = require('xorm')
ESM import works; CJS require also supported but may miss default export. Model is named export.
xorm
import xorm from 'xorm'
const xorm = require('xorm')
Default export is an object containing Model and other utilities. Use ESM default import if you need the whole object.
QueryBuilder
import { QueryBuilder } from 'xorm'
import QueryBuilder from 'xorm/QueryBuilder'
QueryBuilder is re-exported from objection; do not import from subpath. Named export only.

Shows setup with knex, automatic timestamps, and soft delete feature. Creates a User model, inserts, soft deletes, and queries trashed.

import { Model } from 'xorm'; import Knex from 'knex'; const knex = Knex({ client: 'sqlite3', connection: { filename: ':memory:' }, useNullAsDefault: true }); Model.knex(knex); class User extends Model { // tableName defaults to 'User' static timestamps = true; static softDelete = true; } async function main() { await knex.schema.createTable('User', table => { table.increments('id').primary(); table.string('name'); table.datetime('createdAt'); table.datetime('updatedAt'); table.datetime('deletedAt'); }); const user = await User.query().insert({ name: 'Alice' }); console.log(user.createdAt); // Date await User.query().where('id', user.id).delete(); // soft delete const deleted = await User.query().onlyTrashed(); console.log(deleted.length); // 1 } main().then(() => process.exit());
Debug
Known issues
breakingxorm extends Objection.js Model; breaking changes in Objection or knex peer deps may affect xorm behavior.
fix
Pin Objection to ^1.6.9 and knex to >=0.19.0 <1.0 as per peer deps. Check compatibility when upgrading.
affects: >=0.7.0
gotchaDefault table naming uses the model class name verbatim (e.g., 'User'). If your table name differs, you must set static tableName explicitly.
fix
Define static get tableName() { return 'actual_table_name'; } in your model.
affects: >=0.0.0
gotchaTimestamps are enabled by default; if your schema lacks createdAt/updatedAt columns, inserts will fail with column not found errors.
fix
Set static timestamps = false; or map column names via timestamps = {createdAt: 'my_created', updatedAt: 'my_updated'}.
affects: >=0.0.0
gotchaSoft delete queries (withTrashed, onlyTrashed, restore) only work when softDelete = true on the model; otherwise they may throw or do nothing.
fix
Ensure model has static softDelete = true; and schema includes 'deletedAt' column (or custom column name).
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'sm-utils'
sm-utils peer dependency not installed.
fix
Run npm install sm-utils@^2.14.5
TypeError: Model.knex is not a function
xorm and knex are not properly imported; knex instance is not passed to Model.
fix
Call Model.knex(knex) with a valid knex instance; ensure knex is installed and imported.
Knex:Error - column createdAt does not exist
Timestamps enabled but schema lacks createdAt column.
fix
Disable timestamps (static timestamps = false) or add the column in migration.
Method not found: withTrashed
Soft delete not enabled or using xorm version before feature was introduced.
fix
Ensure static softDelete = true; if still missing, upgrade xorm to >=0.7.0.
Upgrade
Version history
0.7.6latest on npm
Audit
Dependencies
knexrequiredSQL query builder required by Objection.js; peer dep
objectionrequiredUnderlying ORM; xorm extends its Model class
sm-utilsrequiredUtility library from same author; required for internal helpers
Agent activity
24 hits · last 30 days
node
20
Meta
1
OpenAI (training)
1
Resources
packagexorm
xorm — npm install xorm · libregistry