Registry / database / mevn-orm

mevn-orm

JSON →
library4.2.2jsnpmunverified

A small ActiveRecord-style ORM built on top of Knex.js for Express.js applications. Version 4.2.2 targets Node.js 20+ and ships TypeScript types. It provides a Model base class with CRUD methods (create, find, update, delete), simple database configuration via configureDatabase, and migration helpers (makeMigration, migrateLatest, migrateRollback, etc.). Currently in maintenance mode — core functionality works but new features are limited. Differentiates from Knex by offering an ActiveRecord pattern, but requires Knex as a peer dependency and is tightly coupled to Knex's query builder.

npm install mevn-orm
INSTALL
IMPORT
SIG · MEVN-ORM
M
mevn-orm
databasejavascriptv4.2.2
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 'mevn-orm'
const Model = require('mevn-orm').Model
ESM-only since v4. Use named import. CommonJS require will fail.
configureDatabase
import { configureDatabase } from 'mevn-orm'
import configureDatabase from 'mevn-orm'
configureDatabase is a named export, not a default export. Cannot be imported as default.
DB
import { DB } from 'mevn-orm'
import { DB } from 'mevn-orm/config'
DB is a Knex instance exported directly from the package root. No subpath imports.

Initializes Mevn ORM with MySQL, defines a User model, creates a record, and retrieves it by ID.

import { configureDatabase, Model } from 'mevn-orm'; import knex from 'knex'; import 'mysql2'; configureDatabase({ client: 'mysql2', connection: { host: process.env.DB_HOST ?? 'localhost', user: process.env.DB_USER ?? 'root', password: process.env.DB_PASSWORD ?? '', database: process.env.DB_NAME ?? 'test' } }); class User extends Model { static tableName = 'users'; fillable = ['name', 'email']; } async function main() { const user = await User.create({ name: 'Alice', email: 'alice@example.com' }); console.log('Created:', user); const found = await User.find(user.id as number); console.log('Found:', found); } main().catch(console.error);
Debug
Known issues
breakingVersion 4.x is ESM-only and requires Node.js 20+. CommonJS require() will throw an error.
fix
Use ES module syntax (import) and ensure Node.js >=20.
affects: >=4.0.0
breakingVersion 4.x changed Model API: fillable and hidden are instance properties, not static.
fix
Define fillable and hidden as instance properties (override keyword) in your model classes.
affects: >=4.0.0
deprecatedModel.save() method is deprecated in favor of create() and update().
fix
Use Model.create() for new records and Model.update() for existing ones.
affects: >=4.0.0
gotchaconfigureDatabase() must be called before any model operations. Calling it multiple times throws an error.
fix
Call configureDatabase() once at application startup, e.g., in a server plugin or main entry point.
affects: >=4.0.0
gotchaKnex must be installed as a peer dependency. Missing knex will cause runtime errors.
fix
Run npm install knex alongside mevn-orm.
affects: >=4.0.0
gotchaTypeScript types may not be fully accurate for dynamically defined model properties.
fix
Cast model instances or use type assertions when accessing dynamic attributes.
affects: >=4.0.0
Errors
Common errors & fixes
Error: Cannot find module 'knex'
Knex is a peer dependency and not installed.
fix
npm install knex
TypeError: mevn_orm_1.configureDatabase is not a function
Using default import instead of named import.
fix
Use import { configureDatabase } from 'mevn-orm'
Error: Must configure the database before using models
configureDatabase() was not called before model operations.
fix
Call configureDatabase() with valid config at startup.
TypeError: Class extends value undefined is not a constructor or null
Trying to import Model in CommonJS (require).
fix
Switch to ESM (import) or use dynamic import.
Upgrade
Version history
4.2.2latest on npm
Audit
Dependencies
knexrequiredPeer dependency required for database query building and migrations
mysql2optionalPeer dependency for MySQL database driver
sqlite3optionalPeer dependency for SQLite database driver
Agent activity
2 hits · last 30 days
node
2
Resources
mevn-orm — npm install mevn-orm · libregistry