Registry / database / mio-mysql

mio-mysql

JSON →
library0.9.0jsnpmunverified

MySQL storage plugin for Mio, an ODM/ORM-style data access library. Current stable version is 0.9.0. This plugin provides MySQL integration for Mio models, supporting common query methods, pagination, custom table/column names, and date handling via node-mysql connection pools. Key differentiators include a Mongo-SQL-like query syntax, automatic pagination metadata on collections, and support for data formatters. Release cadence appears low; no recent updates. Consider alternatives like Sequelize or TypeORM for actively maintained database tooling.

npm install mio-mysql
INSTALL
IMPORT
SIG · MIO-MYSQL
M
mio-mysql
databasejavascriptv0.9.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 mysqlPlugin from 'mio-mysql'
const mysqlPlugin = require('mio-mysql')
Default export is a function that creates a plugin instance.
mysql
import { mysql } from 'mio-mysql'
import { mysql } from 'mio-mysql' (but used as mysql.createConnection instead of mysql module)
Named export 'mysql' exposes the underlying node-mysql module for advanced use.
MioModel
// Not exported directly; use mio.createModel() then attach plugin
import { User } from 'mio-mysql'
mio-mysql does not export models; you must define models with the 'mio' package.

Demonstrates setting up a Mio model with MySQL plugin, defining attributes, saving a record, and executing a find query with pagination.

const mio = require('mio'); const mysqlPlugin = require('mio-mysql'); const User = mio.createModel('User'); User.server(mysqlPlugin({ database: 'mydb', user: 'root', password: 'password' }, { tableName: 'users', maxLimit: 100 })); User.attr('id', { type: 'number' }); User.attr('name', { type: 'string' }); // Save a user const newUser = User.create({ name: 'Alice' }); newUser.save(function(err, user) { if (err) console.error(err); else console.log('User saved:', user); }); // Find users User.findAll() .where({ name: { $like: '%A%' } }) .sort({ name: 'asc' }) .limit(10) .exec(function(err, users) { console.log(users); console.log('Total:', users.total); });
Debug
Known issues
gotchaDefault date columnType is 'integer' (UNIX timestamp), not MySQL DATETIME.
fix
Specify columnType: 'datetime' in attribute definition for human-readable dates.
affects: >=0.1.0
gotchaQuery timeout default is 60 seconds. Long queries will silently destroy the connection.
fix
Set settings.queryTimeout to a higher value or 0 to disable.
affects: >=0.1.0
deprecatedDepends on unmaintained node-mysql (mysql package). Consider using mysql2 driver manually.
fix
Use a fork or migrate to an alternative ORM that supports mysql2.
affects: >=0.1.0
gotchaPlugin must be attached to model via .server() before any queries; otherwise operations may fail silently.
fix
Always call Model.server(mysqlPlugin(...)) before using the model.
affects: >=0.1.0
Errors
Common errors & fixes
Error: Cannot find module 'mio'
Missing peer dependency 'mio'.
fix
Run 'npm install mio' alongside mio-mysql.
Error: Connection lost: The server closed the connection.
Query timeout (default 60s) exceeded.
fix
Increase settings.queryTimeout in the plugin options.
ER_NO_DEFAULT_FOR_FIELD: Field 'id' doesn't have a default value
Missing auto-increment or default for primary key in database table.
fix
Ensure your MySQL table has an AUTO_INCREMENT primary key or provide default values in model.
TypeError: User.findAll is not a function
Model not properly initialized or plugin not attached.
fix
Ensure you called User.server(require('mio-mysql')(...)) before using findAll.
Upgrade
Version history
0.9.0latest on npm
Audit
Dependencies
miorequiredPeer dependency; provides the model system.
mysqlrequiredUnderlying MySQL driver (node-mysql).
Agent activity
2 hits · last 30 days
node
2
Resources
mio-mysql — npm install mio-mysql · libregistry