Registry / database / node-mysql

node-mysql

JSON →
library0.4.2jsnpmunverified

An enhancement to the mysql npm package providing easy transaction handling, a simple ORM with automatic schema detection, optimistic locking, automatic timestamp management, and row-level locking. Current stable version is 0.4.2. The package wraps the popular mysql driver and adds convenience features. It depends on better-js-class, cps, mysql, and underscore. Unlike higher-level ORMs, it remains close to the raw SQL layer while offering transaction, cursor, and table/row abstraction. Release cadence is irregular, with last update in 2016, indicating maintenance mode.

npm install node-mysql
INSTALL
IMPORT
SIG · NODE-MYSQL
N
node-mysql
databasejavascriptv0.4.2
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.

DB
const { DB } = require('node-mysql');
const DB = require('node-mysql').DB;
Works with CommonJS only; no ESM support. Destructure from the default import.
Row
const { Row } = require('node-mysql');
const Row = require('node-mysql').Row;
Row is a class for ORM row instances.
Table
const { Table } = require('node-mysql');
const Table = require('node-mysql').Table;
Table is a class for ORM table operations.
db
const db = require('node-mysql');
import db from 'node-mysql';
This is an old package; use CommonJS require. ES imports will fail.

Shows basic setup: create DB instance with transaction support, define ORM classes, connect, and run a transaction with row creation.

const { DB, Row, Table } = require('node-mysql'); const db = new DB({ host: 'localhost', user: 'root', password: process.env.MYSQL_PASSWORD ?? '', database: 'test', useTransaction: { connectionLimit: 1 } }); // Define a table class class MyTable extends Table { get name() { return 'my_table'; } } // Define a row class class MyRow extends Row {} // Associate table with row MyTable.prototype.rowClass = MyRow; db.add(MyTable); // Use with callback (CPS style) db.connect(function(err) { if (err) throw err; db.transaction(function(conn, cb) { const table = db.get(MyTable); table.create({ name: 'Alice' }, function(err, row) { if (err) return cb(err); console.log('Created row id:', row.getId()); cb(); }); }, function(err) { if (err) throw err; db.end(); }); });
Debug
Known issues
gotchaTransaction methods require useTransaction config, otherwise db.transaction() throws 'transaction-not-setup-error'.
fix
Add useTransaction field to DB constructor options (e.g., { useTransaction: { connectionLimit: 1 } }).
affects: >=0.0.1
gotchaCursor methods require useCursor config, otherwise db.cursor() throws 'cursor-not-setup-error'.
fix
Add useCursor field to DB constructor options.
affects: >=0.0.1
deprecatedThis package is no longer actively maintained; last update in 2016. Use modern alternatives like mysql2, knex, or sequelize.
fix
Migrate to a maintained MySQL library.
affects: >0.4.2
breakingThe package uses continuation-passing style (callbacks) via cps library; promises or async/await are not natively supported.
fix
Wrap callbacks in promises manually or use promisify.
affects: >=0.0.1
Errors
Common errors & fixes
transaction-not-setup-error
Attempting to call db.transaction() without setting the 'useTransaction' configuration option.
fix
Add { useTransaction: { connectionLimit: 1 } } to the DB constructor options.
cursor-not-setup-error
Attempting to call db.cursor() without setting the 'useCursor' configuration option.
fix
Add { useCursor: { ... } } to the DB constructor options.
Cannot find module 'better-js-class'
Missing dependency better-js-class, which is required by node-mysql.
fix
Run npm install to install all dependencies.
Upgrade
Version history
0.4.2latest on npm
Audit
Dependencies
mysqlrequiredCore database driver used for MySQL connections
better-js-classrequiredProvides class inheritance utilities used internally
cpsrequiredContinuation-passing style flow control library
underscorerequiredUtility library for object/array manipulation
Agent activity
4 hits · last 30 days
node
4
Resources
node-mysql — npm install node-mysql · libregistry