Registry / database / modli-mysql

modli-mysql

JSON →
library3.1.0jsnpmunverified

Modli adapter for MySQL databases, providing standard CRUD operations, raw query execution, table creation, and adapter extension. Current stable version is 3.1.0. Provides integration with the Modli data modeling framework. Key differentiators include tight coupling with Modli's model system and a simple API for querying and managing MySQL tables. Released under the MIT license.

npm install modli-mysql
INSTALL
IMPORT
SIG · MODLI-MYSQL
M
modli-mysql
databasejavascriptv3.1.0
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.

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));
Debug
Known issues
gotchatableName must be provided in model definition when using MySQL adapter
fix
Add 'tableName' property to model.add() configuration
affects: *
gotchaQuery conditions in read/update/delete are raw SQL strings, not parameterized queries; risk SQL injection
fix
Sanitize inputs or use parameterized queries via raw 'query' method
affects: *
deprecatedThe 'mysql' npm package (used internally) is deprecated; newer MySQL drivers exist
fix
Consider switching to 'mysql2' for better security and performance
affects: >=3.0.0
Errors
Common errors & fixes
Error: Cannot find module 'modli'
Missing modli core dependency
fix
Run '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
fix
Install '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
fix
Ensure model.add() and adapter.add() are called before calling use()
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies
modlirequiredCore Modli framework required for model and adapter management
mysqlrequiredMySQL driver for Node.js used for database connectivity
Agent activity
4 hits · last 30 days
node
4
Resources
modli-mysql — npm install modli-mysql · libregistry