Registry / database / machinepack-mysql

machinepack-mysql

JSON →
library5.0.0jsnpmunverified

MySQL database driver for Sails.js and Waterline ORM, implementing the Node-Machine driver interface. Version 5.0.0 is the latest stable release, maintained by the Sails.js team. It provides structured, promise-based operations for MySQL databases. Compared to direct mysql2 usage, it integrates seamlessly with Sails/Waterline and enforces a machine-based interface. Active development with regular releases aligned with Sails.js updates.

npm install machinepack-mysql
INSTALL
IMPORT
SIG · MACHINEPACK-MYSQL
M
machinepack-mysql
databasejavascriptv5.0.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
const MySQL = require('machinepack-mysql');
import MySQL from 'machinepack-mysql';
This package is CJS-only; ES modules are not supported. Use require().
getConnection
MySQL.getConnection({ user: 'root', password: '...', database: 'test' }).exec({ error: err => console.log(err), success: conn => console.log(conn) });
MySQL.getConnection({ user: 'root' }, (err, conn) => {});
The API uses .exec() with callbacks or promises, not standard callback pattern. See machine docs.
sendQuery
MySQL.sendQuery({ connection: conn, query: 'SELECT 1' }).exec(console.log);
MySQL.sendQuery(conn, 'SELECT 1').then(console.log);
Requires a connection object from getConnection. Does not return a promise natively; use .exec() or promisify.

Demonstrates connecting to MySQL, executing a CREATE TABLE query, and handling errors with the machine.exec interface.

const MySQL = require('machinepack-mysql'); MySQL.getConnection({ user: 'root', password: process.env.MYSQL_PASSWORD ?? '', database: 'test' }).exec({ error: err => { console.error('Connection error:', err); }, success: conn => { MySQL.sendQuery({ connection: conn, query: 'CREATE TABLE IF NOT EXISTS users (id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255))', values: [] }).exec({ error: err => { console.error('Query error:', err); conn.end(); }, success: () => { console.log('Table created'); conn.end(); } }); } });
Debug
Known issues
breakingIn v5.0.0, the driver interface changed significantly. Old v3/v4 code using .exec() with machinepack-mysql may not work without migration to the new machine definitions.
fix
Refer to the driver-interface spec at https://github.com/node-machine/driver-interface for updated API usage.
affects: >=5.0.0
gotchaThe .exec() method expects an object with callbacks, not a function directly. Using .exec(callback) may cause unexpected behavior.
fix
Use .exec({ success: callback, error: errCallback }) or .toPromise() for promises.
affects: >=4.0.0
deprecatedThe old callback-based .exec(cb) pattern is deprecated. The new API requires an object or promise chain.
fix
Update to .exec({ success, error }) or use machines' .toPromise() method.
affects: >=4.0.0
gotchaConnections obtained from getConnection must be manually ended via conn.end(). Failure to do so causes connection leaks.
fix
Always call conn.end() in success or error handlers.
affects: >=3.0.0
deprecatedThe use of mysql (original) npm package is replaced by mysql2 in v5.0.0. Direct mysql configuration options may need adjustment.
fix
Review mysql2 documentation for connection options differences.
affects: >=5.0.0
Errors
Common errors & fixes
Error: `machinepack-mysql` requires a machinepack that supports the `machine` runtime. Please install `machine` as a dependency.
The 'machine' package is not installed or not available.
fix
Run `npm install machine` to add the required runtime dependency.
TypeError: MySQL.getConnection is not a function
Using ES module import syntax instead of CommonJS require.
fix
Replace `import MySQL from 'machinepack-mysql'` with `const MySQL = require('machinepack-mysql')`.
TypeError: conn.end is not a function
The connection object was not properly obtained via getConnection's success callback, or the connection is already closed.
fix
Ensure you save the connection passed to the success callback and call .end() on it, not on the machine result.
Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client
MySQL server uses an authentication plugin (e.g., caching_sha2_password) not supported by mysql2 version.
fix
Upgrade machinepack-mysql to latest version which uses updated mysql2, or set default authentication plugin in MySQL server to mysql_native_password.
Upgrade
Version history
5.0.0latest on npm
Audit
Dependencies
@sailshq/lodashrequiredUtility functions for internal operations
flaverrrequiredError handling utilities
machinerequiredCore machine framework required for building machines
mysql2requiredUnderlying MySQL client library
qsrequiredQuery string parsing
utilexrequiredUtility library for various operations
Agent activity
14 hits · last 30 days
node
12
Resources
machinepack-mysql — npm install machinepack-mysql · libregistry