Registry / database / mysql-wrap

mysql-wrap

JSON →
library0.5.3jsnpmunverified

A lightweight wrapper around the node-mysql driver providing promise-based query methods (select, insert, update, delete) along with helper functions like selectOne and row count. Version 0.5.3 is the latest release; last updated in 2016. It wraps node-mysql and supports connection pooling and pool clusters with read/write separation. Key differentiators: simpler API, built-in promise support via Q library, and pagination helpers. Not actively maintained; alternatives include mysql2 or knex.

npm install mysql-wrap
INSTALL
IMPORT
SIG · MYSQL-WRAP
M
mysql-wrap
databasejavascriptv0.5.3
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 createMySQLWrap = require('mysql-wrap'); const sql = createMySQLWrap(connection);
import createMySQLWrap from 'mysql-wrap';
This package uses CommonJS, not ESM. Default export is a function that expects a connection or pool.
createMySQLWrap (as default)
const sql = require('mysql-wrap')(connection);
import { createMySQLWrap } from 'mysql-wrap';
The module exports a single factory function; no named exports.
require('mysql')
const mysql = require('mysql');
import mysql from 'mysql';
Requires the 'mysql' package as a peer dependency.

Demonstrates creating a connection, wrapping it with mysql-wrap, and executing a simple SELECT query using promises.

const mysql = require('mysql'); const createMySQLWrap = require('mysql-wrap'); const connection = mysql.createConnection({ host: process.env.DB_HOST ?? 'localhost', user: process.env.DB_USER ?? 'user', password: process.env.DB_PASSWORD ?? '', database: process.env.DB_NAME ?? 'test' }); const sql = createMySQLWrap(connection); sql.query('SELECT 1 + 1 AS solution').then((res) => { console.log(res); }).catch((err) => { console.error(err); }).finally(() => { connection.end(); });
Debug
Known issues
deprecatedPackage is no longer maintained; last release in 2016. Use mysql2 or knex for modern projects.
fix
Migrate to mysql2 which supports promises natively or use knex for a query builder.
affects: >=0
gotchaAll methods return Q promises, not native ES6 promises. May cause incompatibility with async/await in older Node versions.
fix
Use Q.nfcall or convert with Promise.resolve(). Ensure Q is available.
affects: <0.5
breakingThe default export is a function that requires a connection or pool; passing an incorrect argument (e.g., options object) will throw.
fix
Always pass a valid mysql connection, pool, or poolCluster.
affects: >=0
gotchaConnection pooling requires passing a pool object, not a connection; using a connection with pool methods may cause errors.
fix
Check if you need a single connection or pool and pass the correct object.
affects: >=0
Errors
Common errors & fixes
Cannot find module 'mysql-wrap'
Package not installed or not found in node_modules.
fix
Run `npm install mysql-wrap` and ensure correct path.
TypeError: createMySQLWrap is not a function
Incorrect import style (ESM import used on CJS module).
fix
Use `const createMySQLWrap = require('mysql-wrap');` instead of `import`.
Connection lost: The server closed the connection.
MySQL server timeout or network issues; mysql-wrap does not auto-reconnect.
fix
Implement connection retry logic or use mysql2 with promise wrapper.
Upgrade
Version history
0.5.3latest on npm
Audit
Dependencies
mysqlrequiredPeer dependency: wraps node-mysql driver
qrequiredPromise library used internally
Agent activity
4 hits · last 30 days
node
4
Resources
mysql-wrap — npm install mysql-wrap · libregistry