Registry / database / mysql-singleton

mysql-singleton

JSON →
library1.0.5jsnpmunverified

A minimal singleton wrapper around the MySQL npm driver that provides a single shared connection pool. Currently at version 1.0.5, last updated in 2018. It offers both callback-based and Promise-based connection retrieval. Differentiators: extremely simple API, but lacks connection management features and is not actively maintained. Consider using mysql2 or knex for production.

npm install mysql-singleton
INSTALL
IMPORT
SIG · MYSQL-SINGLETON
M
mysql-singleton
databasejavascriptv1.0.5
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.

mysql_singleton
const mysql_singleton = require('mysql-singleton');
import mysql_singleton from 'mysql-singleton';
Package is CommonJS-only, no ESM support.
config
mysql_singleton.config({host:'localhost',user:'root',password:'',database:'test'});
mysql_singleton.config({ host: 'localhost', user: 'root' });
Config must include 'database' property; missing it will cause runtime errors.
getConnection
mysql_singleton.getConnection(function(err, connection) { ... });
const conn = await mysql_singleton.getConnection();
getConnection does not return a Promise; use getConnectionPromise for async/await.

Shows basic usage: configure the singleton, get a connection asynchronously, run a query, and release the connection.

const mysql_singleton = require('mysql-singleton'); const config = { host: 'localhost', user: 'root', password: '', database: 'test_db' }; mysql_singleton.config(config); async function query() { const connection = await mysql_singleton.getConnectionPromise(); connection.query('SELECT 1 AS result', (err, results) => { if (err) throw err; console.log(results); connection.release(); }); } query().catch(console.error);
Debug
Known issues
deprecatedPackage is unmaintained and relies on the legacy 'mysql' driver, which has known security issues.
fix
Migrate to mysql2 or knex for active support and security patches.
affects: >=1.0.0
gotchagetConnection does not return a Promise; calling it without a callback will silently fail.
fix
Use getConnectionPromise for async/await or pass a callback to getConnection.
affects: >=1.0.0
gotchaConfig must include 'database' property; otherwise getConnection will error with 'No database selected'.
fix
Ensure the config object includes a 'database' property.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'mysql'
The underlying 'mysql' package is not installed.
fix
Run 'npm install mysql' as a peer dependency.
TypeError: mysql_singleton.getConnection is not a function
The package cannot be found or the import is incorrect.
fix
Ensure the package is installed: 'npm install mysql-singleton' and required correctly.
Upgrade
Version history
1.0.5latest on npm
Audit
Dependencies
mysqlrequiredUnderlying MySQL driver used for all database operations
Agent activity
2 hits · last 30 days
node
2
Resources
mysql-singleton — npm install mysql-singleton · libregistry