Registry / database / ali-h-mysql-ts

ali-h-mysql-ts

JSON →
library1.3.17jsnpmunverified

A lightweight TypeScript-friendly MySQL client for Node.js that provides a fluent API for query construction, inserts, updates, and deletes. Version 1.3.17 (latest) is actively maintained with monthly releases. Unlike raw mysql2 or knex, it offers a chainable builder pattern inspired by LINQ, supports automatic pagination, join, and subquery helpers. Includes TypeScript definitions, ES module and CommonJS support. Targets Node.js 8+.

npm install ali-h-mysql-ts
INSTALL
IMPORT
SIG · ALI-H-MYSQL-TS
A
ali-h-mysql-ts
databasejavascriptv1.3.17
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
import DbClient from 'ali-h-mysql-ts'
const DbClient = require('ali-mysql-client')
Package is ali-h-mysql-ts, not ali-mysql-client. Default import works in ESM.
default (CJS)
const DbClient = require('ali-h-mysql-ts')
import DbClient from 'ali-h-mysql-ts'
Works in CommonJS; ESM import also supported.
literals
import { literals } from 'ali-h-mysql-ts'
const literals = require('ali-mysql-client').literals
Named export for SQL literals like now, true, false.

Demonstrates basic CRUD operations: insert, select (findOne), update, and delete using the fluent builder pattern.

import DbClient from 'ali-h-mysql-ts'; const db = new DbClient({ host: process.env.DB_HOST ?? 'localhost', port: Number(process.env.DB_PORT ?? 3306), user: process.env.DB_USER ?? 'root', password: process.env.DB_PASSWORD ?? '', database: process.env.DB_NAME ?? 'test', dateStrings: true, timezone: '+08:00' }); async function main() { // Create table await db.raw(`CREATE TABLE IF NOT EXISTS users ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, email VARCHAR(255) )`); // Insert const insertResult = await db .insert('users', { name: 'Alice', email: 'alice@example.com' }) .execute(); console.log('Insert ID:', insertResult.insertId); // Select const user = await db .select('*') .from('users') .where('id', insertResult.insertId) .findOne(); console.log('Found user:', user); // Update await db .update('users') .set('email', 'alice@newdomain.com') .where('id', insertResult.insertId) .execute(); // Delete await db .delete('users') .where('id', insertResult.insertId) .execute(); } main().catch(console.error);
Debug
Known issues
gotchaPackage name ali-h-mysql-ts vs common mistake ali-mysql-client
fix
Use require('ali-h-mysql-ts') or import from 'ali-h-mysql-ts'
affects: >=1.0.0
breakingmysql2 is required as a peer dependency, not bundled
fix
Run npm install mysql2 alongside ali-h-mysql-ts
affects: >=1.0.0
deprecatedRaw queries using db.raw() are not chainable and may be deprecated in future
fix
Use the builder API instead of raw SQL where possible
affects: >=1.0.0
gotchaTimezone option affects date strings; 'Z' offset may cause confusion
fix
Set timezone to '+00:00' for UTC or the appropriate offset
affects: >=1.0.0
breakingESM import may fail in older Node versions (<12) without --experimental-modules
fix
Use CommonJS require() or upgrade Node.js to 12+
affects: >=1.0.0
gotchaNull values in insert/update are treated as SQL NULL, not string 'null'
fix
Explicitly set column values or omit them
affects: >=1.0.0
deprecatedDbClient.literals is a static getter; destructuring literals from the instance may break
fix
Use import { literals } from 'ali-h-mysql-ts' instead of db.literals
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'ali-mysql-client'
Using old package name instead of 'ali-h-mysql-ts'
fix
Install ali-h-mysql-ts (npm install ali-h-mysql-ts) and update require/import
Error: Cannot find module 'mysql2'
mysql2 peer dependency not installed
fix
Run npm install mysql2
TypeError: db.select(...).from is not a function
Calling .from() on a non-chained object, possibly using raw() incorrectly
fix
Ensure you use the builder: db.select('*').from('table')...
Duplicate entry '...' for key 'PRIMARY'
Inserting a row with an existing primary key value
fix
Use .insert() with .onDuplicateKeyUpdate() or check existence first
Upgrade
Version history
1.3.17latest on npm
Audit
Dependencies
mysql2requiredUnderlying MySQL driver for all database operations
Agent activity
22 hits · last 30 days
node
20
OpenAI (training)
1
Resources
ali-h-mysql-ts — npm install ali-h-mysql-ts · libregistry