Registry / database / jm-ez-mysql

jm-ez-mysql

JSON →
library4.0.0jsnpmunverified

jm-ez-mysql is a simple MySQL wrapper for Node.js that provides a promise-based API for common database operations (select, insert, update, delete) with built-in query builder, prepared statement support, and raw query execution. Current stable version is 4.0.0. It wraps the popular `mysql` npm package, offering a higher-level abstraction with methods like `findAll`, `insert`, and `update`, plus a query builder for dynamic conditions. Compared to alternatives like `mysql2/promise`, it provides a more concise API inspired by ORM-like patterns, but lacks connection pooling and prepared statement placeholder support. Release cadence is irregular; version 4.0.0 introduced breaking changes (moved from callback/promise mix to full promise). Differentiators: simple API, built-in query logging (`lQ`), and query builder with `where`/`orWhere`.

npm install jm-ez-mysql
INSTALL
IMPORT
SIG · JM-EZ-MYSQL
J
jm-ez-mysql
databasejavascriptv4.0.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.

My
const My = require('jm-ez-mysql')
import My from 'jm-ez-mysql'
This package does not export an ES module; use CommonJS require. Version 4.x remains CJS.
My.init
My.init({ host: 'localhost', user: 'root', password: '...', database: 'test' })
My.init('localhost', 'root', '...', 'test')
Init takes a single connection configuration object, not positional arguments.
My.findAll
My.findAll('table', ['col1', 'col2'], 'condition', [params])
My.findAll('table', 'col1', 'condition')
The second argument must be an array of column names, even for a single column. The fourth optional argument is an array of parameters for prepared statements.
My.query
My.query('SELECT * FROM users WHERE id = ?', [userId])
My.query('SELECT * FROM users WHERE id = ' + userId)
Always use the parameterized form with `?` placeholders and an array of values to prevent SQL injection.
My.initQuery
const q = My.initQuery(); q.where('id', 1); q.execute('table')
My.initQuery().where('id', 1).execute('table')
`initQuery()` returns a query builder instance; methods like `where` and `execute` are chainable but `execute` returns a promise, not the query object.

Shows common CRUD operations: insert, select, update, and using the query builder. Uses environment variable for password.

const My = require('jm-ez-mysql'); // Initialize connection My.init({ host: 'localhost', user: 'root', password: process.env.DB_PASSWORD ?? '', database: 'test' }); // Insert a record My.insert('users', { name: 'Alice', email: 'alice@example.com' }) .then(result => { console.log('Inserted ID:', result.insertId); }); // Select records with condition My.findAll('users', ['id', 'name'], 'email = ?', ['alice@example.com']) .then(rows => { console.log('User:', rows[0]); }); // Update My.update('users', { name: 'Alice Johnson' }, 'id = ?', [1]) .then(result => { console.log('Rows affected:', result.affectedRows); }); // Using query builder const q = My.initQuery(); q.where('active', 1); q.execute('users').then(rows => { console.log('Active users:', rows.length); });
Debug
Known issues
breakingVersion 4.0.0 changed the API from mix of callbacks and promises to fully promise-based. Old callback-style code will break.
fix
Convert all callback usage to .then()/.catch() or async/await. Example: My.insert('table', data, callback) becomes My.insert('table', data).then(callback).
affects: >=3.0.0 <4.0.0
gotchaThe `findAll` second argument must be an array; passing a plain string will cause unexpected behavior (treats each character as a column).
fix
Always pass columns as an array: `['id', 'name']`, not `'id, name'`.
affects: >=1.0.0
gotchaThe `insertMany` method does not support prepared statements for value arrays; it builds the query directly, potentially leading to SQL injection if values are not sanitized.
fix
Sanitize all values before passing to `insertMany`, or use a loop with `insert` and prepared statements.
affects: >=1.0.0
deprecatedThe `My.lQ` property (last query) is a debugging aid but not a documented public API; relying on it may break in future versions.
fix
Use a proper logging or query intercepting mechanism if needed.
affects: >=1.0.0
gotchaThe `My.escape` method uses the underlying `mysql` package's escape and does not support objects/arrays; passing non-string types may cause runtime errors.
fix
Only pass strings to `My.escape`. For other types, convert them to strings first.
affects: >=1.0.0
gotchaQuery builder's `execute` method does not return the query builder instance, it returns a promise. Chaining after execute will not work as expected.
fix
Do not chain methods after `execute()`. Capture the promise and use .then().
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'jm-ez-mysql'
Package not installed or wrong require path.
fix
Run `npm install jm-ez-mysql --save` and ensure the module is in `node_modules`.
ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)
Invalid MySQL credentials in the My.init configuration.
fix
Check your MySQL host, user, and password. Ensure the MySQL server is running and accepts connections.
TypeError: My.findAll is not a function
My.init() was not called or the module was not properly imported.
fix
Call `My.init({...})` before using any model methods. Ensure `const My = require('jm-ez-mysql')` is correct.
Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '?'
Using `?` placeholder without providing parameters array.
fix
When using `?` in condition, pass an array of parameters as the last argument: `My.findAll('table', ['col'], 'id = ?', [id])`.
Upgrade
Version history
4.0.0latest on npm
Audit
Dependencies
mysqlrequiredThe underlying MySQL driver; jm-ez-mysql wraps the `mysql` package's connection and query functions.
Agent activity
4 hits · last 30 days
node
4
Resources