Registry / database / ali-mysql-client

ali-mysql-client

JSON →
library1.0.7jsnpmunverified

ali-mysql-client (v1.0.7) is a lightweight Node.js MySQL client providing a fluent API for common database operations: select, insert, update, delete, with support for pagination, joins, grouping, ordering, and raw SQL. It wraps the `mysql` package, offering a more expressive chainable builder pattern akin to Knex but simpler. Released under MIT, it is suitable for small to medium projects that need quick MySQL access without ORM overhead.

npm install ali-mysql-client
INSTALL
IMPORT
SIG · ALI-MYSQL-CLIENT
A
ali-mysql-client
databasejavascriptv1.0.7
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
const DbClient = require('ali-mysql-client');
const { DbClient } = require('ali-mysql-client');
Package exports a single constructor via CommonJS. No named export.
DbClient
import DbClient from 'ali-mysql-client';
import { DbClient } from 'ali-mysql-client';
If using ESM, must use default import. The package does not provide native ESM; transpilation required.
new DbClient()
const db = new DbClient({ host, user, password, database });
const db = DbClient({ host, user, password, database });
Missing `new` keyword throws TypeError.

Complete CRUD example: insert, select with pagination, update, and delete using ali-mysql-client fluent API.

const DbClient = require('ali-mysql-client'); const db = new DbClient({ host: process.env.DB_HOST ?? 'localhost', user: process.env.DB_USER ?? 'root', password: process.env.DB_PASS ?? '', database: process.env.DB_NAME ?? 'my_db' }); async function main() { // Insert a row const insertResult = await db .insert('users', { name: 'Alice', age: 30 }) .execute(); console.log('Insert result:', insertResult); // Query rows with pagination const { total, rows } = await db .select('*') .from('users') .where('age', 25, 'ge') .queryListWithPaging(1, 10); console.log(`Total: ${total}, Rows:`, rows); // Update a row const updateResult = await db .update('users') .column('age', 31) .where('name', 'Alice') .execute(); console.log('Update result:', updateResult); // Delete a row const deleteResult = await db .delete('users') .where('name', 'Alice') .execute(); console.log('Delete result:', deleteResult); } main().catch(console.error);
Debug
Known issues
gotchaThe `.where()` method uses operator strings like 'like', 'lt', 'ge' – case insensitive? Not documented. Use lowercase as examples show.
fix
Always use lowercase operator strings: 'like', 'lt', 'gt', 'le', 'ge', 'ne'.
affects: all
breakingPackage does not support connection pooling by default; each `new DbClient()` creates one connection. Pooled connections require manual management.
fix
Consider using `mysql2` pool wrapper or implement pool yourself. Alternatively, use `knex` or `sequelize` for built-in pooling.
affects: all
gotchaQueries are not automatically escaped for operators in `.where()` values that are objects or arrays. Manual `db.literal` needed for raw SQL parts.
fix
Use `db.literal('now()')` for MySQL functions. For arrays, use `db.literal('IN (1,2,3)')` or expand manually.
affects: all
deprecatedThe `.execute()` method returns result from `mysql` package callback – may return `undefined` for some insert/update calls if affectedRows is not requested.
fix
Check documentation return values. Use `.toSql()` to get query string first for debugging.
affects: all
gotchaPackage uses `mysql` (not `mysql2`). `mysql2` has better performance and promises support, but ali-mysql-client expects the old `mysql` API.
fix
Stick with `mysql` package as dependency. Do not replace with `mysql2` without testing compatibility.
affects: all
breakingThe `queryListWithPaging(p, size)` uses 1-based page index. Page 1 is the first page.
fix
Pass page number starting from 1. example: `.queryListWithPaging(1, 10)` for first page of 10 records.
affects: all
Errors
Common errors & fixes
TypeError: DbClient is not a constructor
Missing `new` keyword when instantiating DbClient.
fix
Use `const db = new DbClient({...})` instead of `const db = DbClient({...})`.
Cannot find module 'mysql'
Missing peer dependency `mysql` which is not installed automatically by npm (not in dependencies).
fix
Run `npm install mysql` alongside ali-mysql-client.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost'
Incorrect database credentials or host/port mismatch.
fix
Verify environment variables or hardcoded config: `host`, `user`, `password`, `database`. The library does not use `port` option by default; defaults to 3306.
Upgrade
Version history
1.0.7latest on npm
Audit
Dependencies
mysqlrequiredrequired for MySQL database connection and query execution
Agent activity
25 hits · last 30 days
node
22
OpenAI (training)
1
Resources
ali-mysql-client — npm install ali-mysql-client · libregistry