Registry / database / node-entities

node-entities

JSON →
library2.1.8jsnpmunverified

A lightweight MySQL ORM for Node.js that mimics Mongoose-style chainable queries. Version 2.1.8 is the latest stable release. It operates on 'convention over configuration', deriving table mappings from model names. Supports CRUD operations, transactions, findOne, count, and complex queries via SQL object with and/join. Depends on underscore, x-flow, and node-mysql. Simpler than Sequelize or TypeORM but less feature-rich (no schema creation, migrations, or mapping config).

npm install node-entities
INSTALL
IMPORT
SIG · NODE-ENTITIES
N
node-entities
databasejavascriptv2.1.8
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.

master (factoryMaster)
const master = require('node-entities');
The module exports the factoryMaster object directly. ESM import not supported.
init
master.init(opts, models);
master.init({...}, {...}); // correct usage shown
Returns a Factory constructor class.
Factory
const Factory = master.init(opts, models); const factory = new Factory();
const factory = new master.Factory(); // only after init
Factory class is returned by init, not directly on master before init.

Shows initialization, model definition, insert, and query using node-entities.

const master = require('node-entities'); const models = { user: function User() { this.id = { type: Number }; this.name = { type: String }; this.email = { type: String }; } }; const Factory = master.init({ host: process.env.MYSQL_HOST || 'localhost', port: process.env.MYSQL_PORT || 3306, user: process.env.MYSQL_USER || 'root', password: process.env.MYSQL_PASSWORD || '', database: process.env.MYSQL_DATABASE || 'test' }, models); const factory = new Factory(); // Insert a user factory.save('user', { name: 'Alice', email: 'alice@example.com' }, function(err, result) { if (err) console.error(err); else console.log('Inserted user ID:', result.insertId); // Query users factory.find('user', {}, {}, function(err, users) { if (err) console.error(err); else console.log('Users:', users); }); });
Debug
Known issues
gotchafind() always returns results as an array, even for a single record. Use findOne() for a single object.
fix
Use factory.findOne() when expecting a single object, or handle array result.
affects: >=2.0
breakingv2.0 changed the API: init now returns a Factory class instead of an object. The old master.create() method was removed.
fix
Update code to use new Factory() after init. See quickstart.
affects: >=2.0
gotchaModels must be defined using a function constructor (e.g., function User() {...}) and properties assigned with this. Schema format is limited.
fix
Define models as shown in documentation: function ModelName() { this.field = {type: Type}; }
affects: >=2.0
deprecatedUnderscore dependency is outdated; consider using lodash or native functions.
fix
No immediate fix required, but plan to migrate away from underscore.
affects: >=2.0
Errors
Common errors & fixes
Cannot find module 'x-flow'
Missing dependency x-flow. Not installed automatically.
fix
npm install x-flow
factory.find is not a function
Factory not initialized correctly or factory object not created via new Factory()
fix
Ensure you call master.init() to get Factory, then create instance: const factory = new Factory();
Cannot read property 'insertId' of undefined
Insert callback returns raw mysql result object; insertId is present only if table has auto_increment.
fix
Check if result.insertId exists or use result.affectedRows for non-auto_increment tables.
Upgrade
Version history
2.1.8latest on npm
Audit
Dependencies
underscorerequiredUtility library for object/array manipulation
x-flowrequiredAsynchronous flow control
mysqlrequiredMySQL database driver
Agent activity
2 hits · last 30 days
node
2
Resources
node-entities — npm install node-entities · libregistry