Registry / database / morphine-orm

morphine-orm

JSON →
library0.7.1jsnpmunverified

MorphineOrm (v0.7.1) is an original Promise-based ORM for Node.js that generates only simple SQL queries (never nested SELECTs). It supports MySQL, MariaDB, PostgreSQL, CockroachDB, SQLite, MSSQL, and Oracle. Features include automatic schema synchronization from model definitions, associations (one-to-one, one-to-many, many-to-one), and virtual attributes. Unlike most ORMs, it uses raw SQL conditions after 'where' instead of a proprietary query language, making it both fast and easy to learn. Released under the MIT license, it has a moderate release cadence with recent updates in 2020.

npm install morphine-orm
INSTALL
IMPORT
SIG · MORPHINE-ORM
M
morphine-orm
databasejavascriptv0.7.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.

MorphineOrm
import MorphineOrm from 'morphine-orm'
const MorphineOrm = require('morphine-orm')
Package is ESM-only; CommonJS require will fail. Use import syntax.
Model
// Models are plain objects, no class import needed. // Define models as shown in documentation.
Models are defined as plain JavaScript objects in separate files; they are not imported as classes.
Dogs
const Dogs = require('./models/Dogs.model')();
import Dogs from './models/Dogs.model'
Models are exported as a function that returns a model definition object. CommonJS require is recommended for models; ESM import might not work as expected.

Initialize MorphineOrm with a MySQL connection, define a model file, and create a record.

// Install driver for your database, e.g., MySQL: npm install mysql2 const MorphineOrm = require('morphine-orm'); const mysql2 = require('mysql2'); // Initialize ORM with database configuration const orm = new MorphineOrm({ adapters: { 'default': 'mysql', 'mysql': { module: mysql2, host: process.env.DB_HOST ?? 'localhost', port: process.env.DB_PORT ?? 3306, user: process.env.DB_USER ?? 'root', password: process.env.DB_PASSWORD ?? '', database: process.env.DB_NAME ?? 'test' } }, connections: { 'default': { adapter: 'mysql' } }, defaults: { migrate: 'alter' // Auto-sync schema }, models: [__dirname + '/models'] // Directory with model files }); // Define a model (e.g., /models/Dogs.model.js) // module.exports = function() { // return { // tableName: 'dogs', // attributes: { // id: { type: 'integer', autoincrement: true, primary: true }, // name: { type: 'string', defaultsTo: '' }, // birth: { type: 'date', defaultsTo: '0000-00-00' } // } // }; // } // Usage (after ORM initialized) const Dogs = orm.models.Dogs; async function createDog() { const dog = await Dogs.create({ name: 'Rex', birth: '2019-10-06' }).exec(); console.log('Created dog:', dog); } createDog().catch(err => console.error(err));
Debug
Known issues
gotchaModels must be exported as functions returning plain objects; using class-based models will not work.
fix
Wrap model definition in a function: module.exports = function() { return { attributes: {...} }; };
affects: >=0
gotchaSQL injection risk when using raw SQL in find/update methods. The library accepts raw conditions after 'where' without parameterized queries unless using the array format.
fix
Use parameterized queries with array syntax: Dogs.find('name=?', ['Rex']).exec(); instead of string interpolation.
affects: >=0
deprecatedThe 'autoincrement' attribute type may not work with all database drivers; use 'id: { type: 'integer', autoincrement: true }' as documented, but some drivers require additional configuration.
fix
Refer to driver-specific documentation for auto-increment column setup.
affects: >=0
Errors
Common errors & fixes
Cannot find module 'morphine-orm'
Package not installed or wrong import syntax for ESM/CommonJS.
fix
Ensure installed: npm install morphine-orm. If using CommonJS, use require('morphine-orm').
MorphineOrm is not a constructor
Using CommonJS require with ESM package or vice versa.
fix
Use ESM import: import MorphineOrm from 'morphine-orm';
Model is not defined
Model file not properly exported or path not set correctly.
fix
Model must export a function returning an object with 'attributes' key. Check models directory path in ORM config.
No database adapter found
Missing database driver or incorrect adapter name.
fix
Install appropriate driver (e.g., mysql2, pg, sqlite3) and configure adapter with 'module' key.
Upgrade
Version history
0.7.1latest on npm
Audit
Dependencies
mysql2optionalRequired driver for MySQL or MariaDB; alternative: mysql
pgoptionalRequired driver for PostgreSQL or CockroachDB
sqlite3optionalRequired driver for SQLite
mssqloptionalRequired driver for Microsoft SQL Server
oracledboptionalRequired driver for Oracle Database
Agent activity
2 hits · last 30 days
node
2
Resources
morphine-orm — npm install morphine-orm · libregistry