Registry / database / led-mysql

led-mysql

JSON →
library1.0.4jsnpmunverified

A lightweight MySQL wrapper for Node.js that provides a simplified API for common database operations including query, insert, update, and unique ID generation. Version 1.0.4 is current, with no recent updates or breaking changes. The library wraps the mysql package and adds connection resilience with automatic reconnection attempts. It is designed for small to medium projects where simplicity is preferred over full-featured ORMs like Sequelize or Knex. The API is promise-based and supports async/await. The package is stable but lightly maintained.

npm install led-mysql
INSTALL
IMPORT
SIG · LED-MYSQL
L
led-mysql
databasejavascriptv1.0.4
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.

dbConnection
const dbConnection = require('led-mysql');
import dbConnection from 'led-mysql';
This package does not have a default ESM export. Use CommonJS require. The function returned by require is a factory that takes a config object.
query
const db = dbConnection(config); const result = await db.query('SELECT * FROM table');
const { query } = require('led-mysql');
query is a method on the database instance, not a separate export. You must create a connection first.
insert
const db = dbConnection(config); const lastId = await db.insert('users', { name: 'John' });
db.insert('users', ['name'], ['John']);
insert expects an object (key-value pairs) for the data parameter, not arrays. Returns the inserted ID.

Shows how to create a connection, execute a query with parameters, insert a record, and close the connection. Uses CommonJS require.

const dbConnection = require('led-mysql'); const config = { host: 'localhost', user: 'root', password: process.env.DB_PASSWORD ?? '', database: 'test_db', maxAttempts: 5 }; const db = dbConnection(config); async function run() { try { const rows = await db.query('SELECT * FROM users WHERE id = ?', [1]); console.log(rows); const newId = await db.insert('users', { name: 'Alice', email: 'alice@example.com' }); console.log('Inserted ID:', newId); } catch (err) { console.error(err); } finally { db.close(); } } run();
Debug
Known issues
gotchaThe library uses the mysql package which is known for not supporting prepared statements by default - queries are escaped but not prepared.
fix
Use parameterized queries as shown in examples to prevent SQL injection. Avoid string concatenation.
affects: >=1.0.0
gotchaThe close() method must be called to release the connection; otherwise, the process may hang.
fix
Always call db.close() after finishing database operations, especially in long-running scripts.
affects: >=1.0.0
deprecatedThe mysql package is in maintenance mode and recommends using mysql2 for modern applications.
fix
Consider using mysql2-based wrappers like mysql2 or knex for better performance and features.
affects: >=1.0.0
gotchaThe returned db object is not a singleton - each call to dbConnection(config) creates a new connection pool. Misuse can lead to connection leaks.
fix
Reuse the same db instance across your application instead of calling dbConnection multiple times.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'led-mysql'
Package not installed or typo in require path.
fix
Run 'npm install led-mysql' and ensure the require path is correct: 'led-mysql' (no leading ./).
TypeError: dbConnection is not a function
Incorrect import style (e.g., using ESM import instead of CommonJS require).
fix
Use const dbConnection = require('led-mysql');
TypeError: Cannot read properties of undefined (reading 'query')
Forgetting to call dbConnection(config) before using db methods.
fix
Create a connection object first: const db = dbConnection(config); then use db.query().
Error: ER_BAD_FIELD_ERROR: Unknown column 'x' in 'field list'
Column name in insert/update object doesn't match database schema.
fix
Ensure the property names in the data object correspond exactly to column names in the table.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
mysqlrequiredCore dependency: uses mysql package under the hood for actual MySQL connection and queries.
Agent activity
4 hits · last 30 days
node
4
Resources
led-mysql — npm install led-mysql · libregistry