Registry / database / mysql-easy

mysql-easy

JSON →
library0.3.3jsnpmunverified

A lightweight promise-based wrapper around the mysql package (version 2.x) that simplifies common database operations like select, insert, update, and delete. Version 0.3.3 is the current stable release; the package has seen no updates for over 5 years and is considered feature-complete. It provides a cleaner API with helper methods for CRUD operations and transaction support, but lacks TypeScript definitions and modern async/await patterns. It is best suited for small to medium projects already using the mysql driver, but for new projects consider more up-to-date alternatives like mysql2 or knex.

npm install mysql-easy
INSTALL
IMPORT
SIG · MYSQL-EASY
M
mysql-easy
databasejavascriptv0.3.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.

mysql-easy (default)
✓ const mysqlEasy = require('mysql-easy');
✗ import mysqlEasy from 'mysql-easy';
Package is CommonJS only; no ESM exports available. Use require() in Node.js.
createPool
✓ const db = mysqlEasy.createPool({...});
✗ const db = mysqlEasy.createConnection({...});
createPool is the typical starting point for connection pooling; createConnection also exists but is rarely used.
query method
✓ db.query('SELECT * FROM users WHERE id = ?', [12]).then(results => ...).catch(err => ...);
✗ db.query('SELECT * FROM users WHERE id = 12').then(results => ...);
Always use parameterized queries to avoid SQL injection; the library does not support raw string interpolation.
insert method
✓ db.insert('users', { user_name: 'foo', age: 30 }).then(result => console.log(result.insertId));
✗ db.insert('users', { user_name: 'foo', age: 30 }).then(result => console.log(result.id));
The result object from insert has insertId, not id.
select
✓ db.select({ table: 'users', where: { id: 12 } }).then(rows => ...);
✗ db.select('users', { id: 12 }).then(rows => ...);
select takes a single object parameter, not separate arguments.

Creates a connection pool, inserts a row, selects rows by condition, and closes the pool using CommonJS require.

const mysqlEasy = require('mysql-easy'); const db = mysqlEasy.createPool({ host: process.env.DB_HOST || 'localhost', database: process.env.DB_NAME || 'test', user: process.env.DB_USER || 'root', password: process.env.DB_PASS || '' }); // Insert a user db.insert('users', { name: 'John', age: 30 }) .then(result => console.log('Inserted ID:', result.insertId)) .catch(err => console.error(err)); // Select users db.select({ table: 'users', where: { age: 30 } }) .then(rows => console.log(rows)) .catch(err => console.error(err)); // Close pool db.end();
Debug
Known issues
breakingVersion 0.3.x changed the API for transaction handling; createTransaction() now returns a promise instead of accepting a callback.
fix
Update code to use .then() or async/await with createTransaction().
affects: 0.3.0
deprecatedThe mysql package (peer dependency) has deprecated the old callback-based API in favor of mysql2. mysql-easy does not support mysql2 and may break with future mysql versions.
fix
Consider migrating to mysql2 or an alternative wrapper like promise-mysql.
affects: >=0.3.0
gotchaWhen using select() with a 'fields' option as an object, field names are used as property names in the result, not as aliases.
fix
Use an array of strings for fields to avoid confusion; the object syntax maps field names to result properties.
affects: >=0.3.0
gotchadelete() and deleteFrom() are aliases; both expect an object or string for the where clause. Omitting where will delete all rows.
fix
Always provide a where condition to avoid accidental mass deletion.
affects: >=0.3.0
gotchaThe library does not handle connection disconnections or reconnections automatically; you must implement retry logic if needed.
fix
Wrap your queries in a retry loop or use a connection pool with built-in recovery.
affects: >=0.3.0
deprecatedThe mysql package (peer dep) last released in 2018; it has several open CVEs related to SQL injection and authentication.
fix
Switch to mysql2 which is actively maintained and provides better security.
affects: >=0.3.0
Errors
Common errors & fixes
Error: Cannot find module 'mysql'
Missing required peer dependency mysql.
fix
Run: npm install mysql
TypeError: mysqlEasy.createPool is not a function
Incorrect import; trying to use ESM default import with a CommonJS module.
fix
Use const mysqlEasy = require('mysql-easy'); instead of import.
TypeError: db.query(...).then is not a function
Query method called with wrong arguments returning undefined or callback-based result.
fix
Ensure query() is called with a string SQL and optional array of params. Check that db is a valid connection/pool.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost'
Invalid database credentials or missing privileges.
fix
Verify host, user, password, and database in the connection config.
Upgrade
Version history
0.3.3latest on npm
Audit
Dependencies
mysqlrequiredruntime peer dependency for actual MySQL protocol handling
Agent activity
9 hits · last 30 days
node
8
Resources
mysql-easy — npm install mysql-easy · libregistry