Registry / database / mysql-easy-query

mysql-easy-query

JSON →
library4.3.0jsnpmunverified

A simple MySQL query wrapper based on mysql2 and sql-easy-builder, providing automatic connection management, connection pooling (including cluster with master-slave separation), transactions, and debugging support. v4.3.0 is the current stable version. It is ESM-only since v4.0. Ships TypeScript types. Key differentiators: minimal configuration, built-in SQL builder for safe queries, easy clustering with pattern/selector support, and automatic connection release. Ideal for Node.js projects needing quick MySQL integration without a full ORM.

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

createPoolCompatible
import { createPoolCompatible } from 'mysql-easy-query'
const createPoolCompatible = require('mysql-easy-query')
ESM-only since v4.0; CommonJS require will fail. Use import syntax.
Query
import { Query } from 'mysql-easy-query'
import Query from 'mysql-easy-query'
Query is a named export, not default.
PoolQuery
import { PoolQuery } from 'mysql-easy-query'
PoolQuery is exported for type use, rarely imported directly.

Shows complete setup of a single pool, inserting a record using the SQL builder, executing a raw query, and closing the pool.

import { createPoolCompatible } from 'mysql-easy-query'; import 'dotenv/config'; const pool = createPoolCompatible({ pools: { master: { host: process.env.DB_HOST ?? '127.0.0.1', user: process.env.DB_USER ?? 'root', database: process.env.DB_NAME ?? 'test', password: process.env.DB_PASS ?? '', } } }); async function main() { // Insert await pool.query(b => b.insert('users', { name: 'Alice', age: 20 })); // Select const users = await pool.query('SELECT * FROM users WHERE age > ?', [18]); console.log(users); await pool.end(); } main().catch(console.error);
Debug
Known issues
breakingv4.0 switched to ESM-only. CommonJS require() will throw a Module not found or ERR_REQUIRE_ESM error.
fix
Use import syntax or upgrade to a CommonJS-compatible version (v3.x).
affects: >=4.0
deprecatedpool.query callback style is deprecated. Use promise-based async/await only.
fix
Refactor to async/await.
affects: >=3.0
gotchaDo not call pool.end() while queries are in flight; it will reject the query promise. Always await all queries before terminating.
fix
Ensure all query async calls are completed before pool.end().
affects: >=0.1
gotchaIn cluster mode, pattern matching is case-sensitive. 'MASTER' vs 'master' may yield no pools.
fix
Double-check pool names in configuration.
affects: >=4.0
breakingv3.2 removed support for callback-based transactions. All transaction callbacks must return a Promise.
fix
Ensure transaction callback is async.
affects: >=3.2
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Using require() on an ESM-only package (v4+).
fix
Change to import syntax: import { createPoolCompatible } from 'mysql-easy-query'.
TypeError: pool.query is not a function
Possibly imported incorrectly or pool is undefined.
fix
Verify the import: import { createPoolCompatible } from 'mysql-easy-query'. Also check that pool was created successfully.
Cannot read properties of undefined (reading 'query')
Calling pool.query before pool is fully initialized, or pool creation failed.
fix
Ensure createPoolCompatible is called with proper config and that the promise is awaited if needed.
ER_ACCESS_DENIED_ERROR: Access denied for user
Wrong credentials or database does not exist.
fix
Check DB_HOST, DB_USER, DB_PASS, and DB_NAME environment variables or configuration.
Upgrade
Version history
4.3.0latest on npm
Audit
Dependencies
mysql2requiredCore MySQL driver for database connections
sql-easy-builderrequiredSQL query builder used by the library
Agent activity
7 hits · last 30 days
node
6
Resources
mysql-easy-query — npm install mysql-easy-query · libregistry