Registry / database / mysql-query-util

mysql-query-util

JSON →
library1.1.1jsnpmunverified

A lightweight MySQL utility for Node.js that simplifies CRUD operations with a declarative, non-SQL-like syntax. Version 1.1.1 provides an abstraction over raw MySQL queries for select, insert, update, and delete operations. It uses a connection pool for efficient database management. Known for its simplicity, it is suitable for small to medium projects but lacks advanced features like migrations, query building, or TypeScript support. Alternative to knex or mysql2/promise.

npm install mysql-query-util
INSTALL
IMPORT
SIG · MYSQL-QUERY-UTIL
M
mysql-query-util
databasejavascriptv1.1.1
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 (mysqlUtil)
const mysqlUtil = require('mysql-query-util');
import mysqlUtil from 'mysql-query-util';
CJS only; does not support ESM imports.

Initializes a MySQL connection pool and performs a select query on the 'users' table using async/await.

const mysqlUtil = require('mysql-query-util'); mysqlUtil.setConnection({ host: process.env.DB_HOST ?? 'localhost', user: process.env.DB_USER ?? 'root', password: process.env.DB_PASSWORD ?? '', database: process.env.DB_NAME ?? 'test', connectionLimit: 25 }); async function main() { const result = await mysqlUtil.select('users'); console.log(result); } main();
Debug
Known issues
gotchaAll methods return a promise; must be awaited or .then() used.
fix
Use async/await or promise chaining.
affects: >=0.0.0
gotchasetConnection must be called before any other method, otherwise throws 'Connection not initialized'.
fix
Call mysqlUtil.setConnection with valid config at startup.
affects: >=0.0.0
gotchaParameters passed as arrays with inline operators: e.g., ['gender', 'like', 'female']. Incorrect ordering or missing operator leads to bad queries.
fix
Ensure each condition array is exactly 3 or 4 elements: [field, operator, value] or ['AND'/'OR', field, operator, value].
affects: >=0.0.0
breakingVersion 1.x uses connection pool; older versions (0.x) used single connection and different initialization.
fix
Upgrade to >=1.0.0 and use setConnection with pool options.
affects: <=1.0.0
Errors
Common errors & fixes
TypeError: mysqlUtil.select is not a function
Incorrect import style (ESM import) or package not installed.
fix
Use require('mysql-query-util') and install package via npm.
Error: Connection not initialized
setConnection not called before making queries.
fix
Invoke mysqlUtil.setConnection({...}) at startup.
Error: Can't set headers after they are sent.
Calling mysqlUtil methods without awaiting, causing multiple responses in Express.
fix
Ensure mysqlUtil calls are awaited in async route handlers.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
mysqlrequiredCore dependency for MySQL database connectivity
Agent activity
2 hits · last 30 days
node
2
Resources
mysql-query-util — npm install mysql-query-util · libregistry