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.
mysqlModelOrm
✓ const mysqlModelOrm = require('mysql-model-orm');
const Model = new mysqlModelOrm({...});
✗ import mysqlModelOrm from 'mysql-model-orm'; // ESM not supported in v2
Package is CommonJS only. Use require().
default export
✓ const Model = require('mysql-model-orm');
const db = new Model({ host: 'localhost', ... });
✗ const db = require('mysql-model-orm')(); // missing new keyword
Must call with new to instantiate.
chaining methods
✓ const result = await db.table('users').where({id: 1}).findOne();
✗ const result = await db.table('users').findOne().where({id: 1}); // where must come before query method
Chain order: table() first, then where/field/order/limit, then query method (select, findOne, etc).
Demonstrates instantiation, table creation, insert, select, update, delete, and transaction usage.
const mysqlModelOrm = require('mysql-model-orm');
const Model = new mysqlModelOrm({
host: 'localhost',
user: 'root',
password: process.env.DB_PASSWORD ?? '',
database: 'test'
});
async function main() {
try {
// Create table if not exists
const createResult = await Model.execsql("CREATE TABLE IF NOT EXISTS users (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255), age INT)");
console.log('Table ready');
// Insert a user
const insertResult = await Model.table('users').add({ name: 'Alice', age: 30 });
console.log('Inserted ID:', insertResult.insertId);
// Query all users
const users = await Model.table('users').select();
console.log('Users:', users);
// Query with condition
const user = await Model.table('users').where({ name: 'Alice' }).findOne();
console.log('Found:', user);
// Update
await Model.table('users').where({ name: 'Alice' }).update({ age: 31 });
// Delete
await Model.table('users').where({ id: 1 }).delete();
// Transaction
await Model.transaction([
Model.table('users').buildSql('add', { name: 'Bob', age: 25 }),
Model.table('users').buildSql('update', { age: 26 }, { name: 'Bob' })
]);
} catch (err) {
console.error(err);
}
}
main();
Errors
Common errors & fixes
TypeError: Model.table is not a function
Missing `new` keyword when instantiating the model.
fixUse `const Model = new mysqlModelOrm({...});` instead of `const Model = require('mysql-model-orm')({...});`. Can't find variable: require
Trying to use require() in an ESM environment (e.g., "type": "module" in package.json).
fixUse `import mysqlModelOrm from 'mysql-model-orm';` if the package supports ESM (it doesn't in v2), or switch to CommonJS by removing "type": "module".
Error: delete() must be used with where()
Calling delete() without a where() clause to prevent accidental mass deletion.
fixAdd `.where(...)` before `.delete()`.
TypeError: Cannot read properties of undefined (reading 'user')
Connection configuration missing or incorrect property names.
fixEnsure config object has 'host', 'user', 'password', 'database', 'port' (optional).
Audit
Dependencies
mysqlrequiredMySQL driver for database connectivity