Registry / database / mysql-easier

mysql-easier

JSON →
library2.1.0jsnpmunverified

A Node.js library (v2.1.0) that provides a simplified interface for MySQL database operations, wrapping the popular mysql package with convenience methods like insert, getById, and deleteById. Supports connection pooling, automatic pool management, or single connections. Last updated in 2023; stable but low-maintenance. Differentiates itself by reducing boilerplate for common CRUD tasks compared to raw mysql usage, but lacks TypeScript types and modern async patterns.

npm install mysql-easier
INSTALL
IMPORT
SIG · MYSQL-EASIER
M
mysql-easier
databasejavascriptv2.1.0
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 (module object)
✓ import mysqlEasier from 'mysql-easier';
✗ const mysqlEasier = require('mysql-easier'); // CJS require still works but TypeScript resolution may be incomplete
ESM import is recommended for new projects; package.json exports support both. The module exports functions like configure, getConnection, createPool, etc.
Pool
✓ import { Pool } from 'mysql-easier'; // Not exported – use module object instead
✗ import { Pool } from 'mysql-easier'; // Pool is not a named export; it's internal
Use createPool() method to get a Pool instance.
Connection
✓ import mysqlEasier from 'mysql-easier'; const conn = await mysqlEasier.getConnection();
✗ import { Connection } from 'mysql-easier'; // Not a named export
Connection instances are returned by getConnection() or createConnection().

Shows how to configure a pool, get a connection, insert a row, retrieve by ID, delete, and release resources.

import mysqlEasier from 'mysql-easier'; // Configure global pool mysqlEasier.configure({ host: process.env.DB_HOST ?? 'localhost', user: process.env.DB_USER ?? 'root', password: process.env.DB_PASS ?? '', database: process.env.DB_NAME ?? 'test' }); (async () => { try { const conn = await mysqlEasier.getConnection(); const newId = await conn.insert('users', { name: 'Alice', email: 'alice@example.com' }); console.log('Inserted ID:', newId); const user = await conn.getById('users', newId); console.log('User:', user); await conn.deleteById('users', newId); await conn.done(); await mysqlEasier.endPool(); } catch (err) { console.error('Error:', err); } })();
Debug
Known issues
gotchaConnections must be released with done() after use; otherwise pool exhaustion occurs.
fix
Always call await conn.done() after finishing database operations, or use a try/finally block.
affects: >=1.0.0
breakingIn v2.0.0, getConnection() returns a Connection instance instead of a raw mysql connection. Methods like insert(), getById() are now on the Connection object.
fix
Update code to use conn.insert() instead of mysqlEasier.insert(). See migration guide in README.
affects: >=2.0.0
deprecatedThe global methods insert(), update(), delete(), etc. are deprecated in v2.x and removed in v3.0.0.
fix
Use instance methods on Connection objects returned by getConnection() or createConnection().
affects: >=2.0.0 <3.0.0
gotchaThe library does not provide TypeScript definition files; users must define their own types.
fix
Install @types/mysql for basic type coverage or create a declaration file for mysql-easier.
affects: >=1.0.0
gotchaThe 'database' option is required in the config object; omission will cause a runtime error.
fix
Always include the 'database' property in the configuration object passed to configure() or createPool().
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'mysql'
mysql-easier depends on mysql which must be installed explicitly.
fix
Run: npm install mysql
TypeError: mysqlEasier.insert is not a function
In v2.x, insert() is a method on Connection instances, not on the module object (global API deprecated).
fix
Use: const conn = await mysqlEasier.getConnection(); await conn.insert(...);
Error: Pool is closed
Attempting to use a connection after calling endPool() or pool.end().
fix
Ensure all database operations complete before closing the pool, and do not reuse connections after pool closure.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
mysqlrequiredCore dependency for MySQL database connectivity; mysql-easier wraps mysql Connection and Pool objects.
Agent activity
9 hits · last 30 days
node
8
Resources
mysql-easier — npm install mysql-easier · libregistry