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.
default
✓ import mysql from 'modli-mysql'
✗ const mysql = require('modli-mysql').default
Default export is the adapter factory function. CJS require() returns the default export directly, no .default needed.
adapterConfig
✓ import mysql from 'modli-mysql'; adapter.add({ name: 'myMysql', source: mysql, config: {...} })
✗ import { MySQL } from 'modli-mysql'
No named exports. The entire module is the adapter function. Use default import and pass to adapter.add().
query
✓ const mysqlTest = use('foo', 'mysqlFoo'); mysqlTest.query('SELECT * FROM tblFoo')
✗ import { query } from 'modli-mysql'
query is a method on the adapter instance returned by use(), not a standalone export.
Shows how to define a model, configure a MySQL adapter, create a record, and read records using the adapter.
import { model, adapter, Joi, use } from 'modli';
import mysql from 'modli-mysql';
model.add({
name: 'foo',
version: 1,
tableName: 'tblFoo',
schema: {
id: Joi.number().integer(),
fname: Joi.string().min(3).max(30),
lname: Joi.string().min(3).max(30),
email: Joi.string().email().min(3).max(254).required()
}
});
adapter.add({
name: 'mysqlFoo',
source: mysql,
config: {
host: process.env.MYSQL_HOST ?? 'localhost',
username: process.env.MYSQL_USER ?? 'root',
password: process.env.MYSQL_PASSWORD ?? '',
database: process.env.MYSQL_DATABASE ?? 'test'
}
});
const mysqlTest = use('foo', 'mysqlFoo');
mysqlTest.create({ fname: 'John', lname: 'Smith', email: 'jsmith@gmail.com' })
.then(result => console.log('Created:', result))
.catch(err => console.error(err));
mysqlTest.read('fname="John"')
.then(rows => console.log('Read:', rows))
.catch(err => console.error(err));
Errors
Common errors & fixes
Error: Cannot find module 'modli'
Missing modli core dependency
fixRun 'npm install modli' to install the core Modli framework
ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server
MySQL server uses caching_sha2_password (default in MySQL 8.0+) but client driver 'mysql' does not support it
fixInstall 'mysql2' instead of 'mysql', or alter user to use mysql_native_password: ALTER USER 'user'@'host' IDENTIFIED WITH mysql_native_password BY 'password'
Cannot read properties of undefined (reading 'query')
Adapter not properly initialized - use() called before model.add() and adapter.add() are completed
fixEnsure model.add() and adapter.add() are called before calling use()
Audit
Dependencies
modlirequiredCore Modli framework required for model and adapter management
mysqlrequiredMySQL driver for Node.js used for database connectivity