Registry / database / mysql-database

mysql-database

JSON →
library1.3.2jsnpmunverified

Easily modify MySQL database data with easy functions. Current stable version is 1.3.2. Provides a simplified API with Promise support and events like connected, dataModification, tableCreate/Delete/Clear/Rename. Methods include set, get, push, pull, add, subtract, exists, clear, delete, and base_set/base_get for encrypted rows. Key differentiator is the event system mirroring library actions. Last updated in 2022, release cadence unknown. Not actively maintained since 2022.

npm install mysql-database
INSTALL
IMPORT
SIG · MYSQL-DATABASE
M
mysql-database
databasejavascriptv1.3.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.

default
const MySQL = require('mysql-database');
import MySQL from 'mysql-database';
Package is CJS, not ESM. Use require() or use dynamic import()
instance.connect
const db = await database.connect({ host: 'localhost', user: 'root', password: '', database: 'test' });
const db = new MySQL({ host: 'localhost' });
connect() is async and returns db instance, don't pass config to constructor
db.on('connected')
db.on('connected', (connection) => { console.log(connection); });
database.on('connected', ...)
Event emitter is the db instance returned by connect(), not the MySQL constructor

Connect to MySQL, set and get a key-value pair, then close connection.

const MySQL = require('mysql-database'); const database = new MySQL(); async function main() { const db = await database.connect({ host: 'localhost', user: 'root', password: process.env.DB_PASSWORD ?? '', database: 'my_database' }); db.on('connected', () => console.log('Connected')); await db.set('users', '1', { name: 'Alice', age: 30 }); const user = await db.get('users', '1'); console.log(user); // { name: 'Alice', age: 30 } await db.end(); } main().catch(console.error);
Debug
Known issues
breakingget method returns null if table does not exist (since v1.3.0).
fix
Check for null or use exists() before get().
affects: >=1.3.0
gotchaEvents are only emitted if action is taken from the library. Manual SQL changes via other clients won't trigger events.
fix
Use library methods to modify data if event tracking is needed.
affects: all
deprecatedThe library has no releases since 2022. The underlying 'mysql' package is also deprecated in favor of 'mysql2'.
fix
Consider migrating to 'mysql2' and using a more maintained wrapper like 'typeorm' or 'knex'.
affects: all
gotchaTable names with uppercase letters may cause 'undefined tables' errors before v1.2.8.
fix
Upgrade to >=1.2.8 or use lowercase table names.
affects: <1.2.8
Errors
Common errors & fixes
TypeError: db.connect is not a function
Calling connect() on the MySQL constructor instead of an instance.
fix
Create an instance first: const db = new MySQL(); then db.connect(...).
Error: ER_BAD_DB_ERROR: Unknown database 'my_database'
Database does not exist. Library does not auto-create databases.
fix
Create the database manually: CREATE DATABASE my_database;
Error: connect ECONNREFUSED
MySQL server not running or wrong host/port.
fix
Ensure MySQL server is running and host/port are correct.
Upgrade
Version history
1.3.2latest on npm
Audit
Dependencies
mysqlrequiredProvides the underlying MySQL connection
Agent activity
2 hits · last 30 days
node
2
Resources
mysql-database — npm install mysql-database · libregistry