{"id":42894,"library":"jm-ez-mysql","title":"jm-ez-mysql","description":"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`.","status":"active","version":"4.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/jay2503/jm-ez-mysql","tags":["javascript","mysql","nodejs","wrapper","helper","node","utility","database"],"install":[{"cmd":"npm install jm-ez-mysql","lang":"bash","label":"npm"},{"cmd":"yarn add jm-ez-mysql","lang":"bash","label":"yarn"},{"cmd":"pnpm add jm-ez-mysql","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"The underlying MySQL driver; jm-ez-mysql wraps the `mysql` package's connection and query functions.","package":"mysql","optional":false}],"imports":[{"note":"This package does not export an ES module; use CommonJS require. Version 4.x remains CJS.","wrong":"import My from 'jm-ez-mysql'","symbol":"My","correct":"const My = require('jm-ez-mysql')"},{"note":"Init takes a single connection configuration object, not positional arguments.","wrong":"My.init('localhost', 'root', '...', 'test')","symbol":"My.init","correct":"My.init({ host: 'localhost', user: 'root', password: '...', database: 'test' })"},{"note":"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.","wrong":"My.findAll('table', 'col1', 'condition')","symbol":"My.findAll","correct":"My.findAll('table', ['col1', 'col2'], 'condition', [params])"},{"note":"Always use the parameterized form with `?` placeholders and an array of values to prevent SQL injection.","wrong":"My.query('SELECT * FROM users WHERE id = ' + userId)","symbol":"My.query","correct":"My.query('SELECT * FROM users WHERE id = ?', [userId])"},{"note":"`initQuery()` returns a query builder instance; methods like `where` and `execute` are chainable but `execute` returns a promise, not the query object.","wrong":"My.initQuery().where('id', 1).execute('table')","symbol":"My.initQuery","correct":"const q = My.initQuery(); q.where('id', 1); q.execute('table')"}],"quickstart":{"code":"const My = require('jm-ez-mysql');\n\n// Initialize connection\nMy.init({\n  host: 'localhost',\n  user: 'root',\n  password: process.env.DB_PASSWORD ?? '',\n  database: 'test'\n});\n\n// Insert a record\nMy.insert('users', { name: 'Alice', email: 'alice@example.com' })\n  .then(result => {\n    console.log('Inserted ID:', result.insertId);\n  });\n\n// Select records with condition\nMy.findAll('users', ['id', 'name'], 'email = ?', ['alice@example.com'])\n  .then(rows => {\n    console.log('User:', rows[0]);\n  });\n\n// Update\nMy.update('users', { name: 'Alice Johnson' }, 'id = ?', [1])\n  .then(result => {\n    console.log('Rows affected:', result.affectedRows);\n  });\n\n// Using query builder\nconst q = My.initQuery();\nq.where('active', 1);\nq.execute('users').then(rows => {\n  console.log('Active users:', rows.length);\n});","lang":"javascript","description":"Shows common CRUD operations: insert, select, update, and using the query builder. Uses environment variable for password."},"warnings":[{"fix":"Convert all callback usage to .then()/.catch() or async/await. Example: My.insert('table', data, callback) becomes My.insert('table', data).then(callback).","message":"Version 4.0.0 changed the API from mix of callbacks and promises to fully promise-based. Old callback-style code will break.","severity":"breaking","affected_versions":">=3.0.0 <4.0.0"},{"fix":"Always pass columns as an array: `['id', 'name']`, not `'id, name'`.","message":"The `findAll` second argument must be an array; passing a plain string will cause unexpected behavior (treats each character as a column).","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Sanitize all values before passing to `insertMany`, or use a loop with `insert` and prepared statements.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use a proper logging or query intercepting mechanism if needed.","message":"The `My.lQ` property (last query) is a debugging aid but not a documented public API; relying on it may break in future versions.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Only pass strings to `My.escape`. For other types, convert them to strings first.","message":"The `My.escape` method uses the underlying `mysql` package's escape and does not support objects/arrays; passing non-string types may cause runtime errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Do not chain methods after `execute()`. Capture the promise and use .then().","message":"Query builder's `execute` method does not return the query builder instance, it returns a promise. Chaining after execute will not work as expected.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'4.0.0':48,107 'abstract':61 'altern':78 'api':22,86,120 'base':21 'break':109 'builder':36,72,129 'built':33,122 'built-in':32,121 'cadenc':103 'callback/promise':113 'chang':110 'common':24 'compar':76 'concis':85 'condit':75 'connect':95 'current':44 'databas':25,140 'delet':30 'differenti':118 'dynam':74 'execut':43 'ez':3,7 'findal':65 'full':116 'helper':137 'higher':59 'higher-level':58 'insert':28,66 'inspir':87 'introduc':108 'irregular':105 'javascript':133 'jm':2,6 'jm-ez-mysql':1,5 'lack':94 'level':60 'like':64,79,91 'log':125 'lq':126 'method':63 'mix':114 'move':111 'mysql':4,8,12,53,134 'mysql2/promise':80 'node':138 'node.js':15 'nodej':135 'npm':54 'offer':56 'oper':26 'orm':90 'orm-lik':89 'orwher':132 'packag':55 'pattern':92 'placehold':100 'plus':69 'pool':96 'popular':52 'prepar':37,98 'promis':20,117 'promise-bas':19 'provid':17,82 'queri':35,42,71,124,128 'raw':41 'releas':102 'select':27 'simpl':11,119 'stabl':45 'statement':38,99 'support':39,101 'updat':29,68 'util':139 'version':46,106 'wrap':50 'wrapper':13,136","created_at":"2026-06-05T16:57:11.183146+00:00","updated_at":"2026-06-05T16:57:11.183146+00:00","problems":[{"fix":"Run `npm install jm-ez-mysql --save` and ensure the module is in `node_modules`.","cause":"Package not installed or wrong require path.","error":"Error: Cannot find module 'jm-ez-mysql'"},{"fix":"Check your MySQL host, user, and password. Ensure the MySQL server is running and accepts connections.","cause":"Invalid MySQL credentials in the My.init configuration.","error":"ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: YES)"},{"fix":"Call `My.init({...})` before using any model methods. Ensure `const My = require('jm-ez-mysql')` is correct.","cause":"My.init() was not called or the module was not properly imported.","error":"TypeError: My.findAll is not a function"},{"fix":"When using `?` in condition, pass an array of parameters as the last argument: `My.findAll('table', ['col'], 'id = ?', [id])`.","cause":"Using `?` placeholder without providing parameters array.","error":"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 '?'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/jay2503/jm-ez-mysql#readme","github":"https://github.com/jay2503/jm-ez-mysql","docs":null,"changelog":null,"pypi":null,"npm":"jm-ez-mysql","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}