Registry / database / hi-mysql

hi-mysql

JSON →
library1.0.17jsnpmunverified

A promise-based wrapper around the mysqljs/mysql library providing connection pooling with master-slave replication support. Current stable version is 1.0.17. Release cadence is low. Key differentiators include simplified failover between master and slave databases and helper methods like queryObject, executeInsert, and executeUpdate that return parsed results directly. It targets Node.js environments and assumes mysqljs/mysql is already installed.

npm install hi-mysql
INSTALL
IMPORT
SIG · HI-MYSQL
H
hi-mysql
databasejavascriptv1.0.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 hi from 'hi-mysql'
const hi = require('hi-mysql')
Package uses ESM default export. CJS require is not supported; use dynamic import or use ESM.
createPool
import hi from 'hi-mysql'; hi.createPool(...)
import { createPool } from 'hi-mysql'
createPool is a method on the default export, not a named export.
Pool
import hi from 'hi-mysql'; const pool: ReturnType<typeof hi.createPool> = hi.createPool({...})
import type { Pool } from 'hi-mysql'
Type definitions are not provided. Use inference or declare manually.

Shows how to import, create a pool with configuration from environment variables, run query and queryObject, then close pool.

import hi from 'hi-mysql'; const master = { host: process.env.MYSQL_HOST ?? 'localhost', port: Number(process.env.MYSQL_PORT) || 3306, user: process.env.MYSQL_USER ?? 'root', password: process.env.MYSQL_PASSWORD ?? '', database: process.env.MYSQL_DATABASE ?? 'test' }; const pool = hi.createPool(master); const rows = await pool.query('SELECT 1 AS result'); console.log(rows); const row = await pool.queryObject('SELECT 1 AS result'); console.log(row); await pool.end();
Debug
Known issues
gotchacreatePool with array of configs uses first as master, rest as slaves. If only one config is provided, it must be a single object, not an array.
fix
Pass a single object or an array with at least one element (master).
affects: >=1.0.0
deprecatedThe underlying mysqljs/mysql package is deprecated and unmaintained. Use mysql2 for continued security updates.
fix
Switch to mysql2 wrapper like 'mysql2/promise' or use a different ORM.
affects: >=1.0.0
gotchaPool.query returns an array of rows; Pool.queryObject returns only the first row (object).
fix
Use query for multiple rows, queryObject for single row.
affects: >=1.0.0
breakingNo TypeScript types are bundled. TypeScript users must manually define types or use 'mysql' package types.
fix
Install @types/mysql and augment or cast types as needed.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'hi-mysql'
Package not installed or wrong import path.
fix
Run 'npm install hi-mysql' and ensure the import path matches the package name.
TypeError: hi.createPool is not a function
Import is not the default export (e.g., named import used).
fix
Use 'import hi from "hi-mysql"' instead of 'import { createPool } from "hi-mysql"'.
Error: connect ECONNREFUSED 127.0.0.1:3306
MySQL server is not running or connection settings are incorrect.
fix
Verify MySQL host, port, and credentials. Ensure the MySQL service is started and accessible.
TypeError: pool.query is not a function
Pool creation failed (e.g., passed an array when single object expected).
fix
Ensure createPool receives a valid configuration object or array. Check that object has required fields (host, user, password, database).
Upgrade
Version history
1.0.17latest on npm
Audit
Dependencies
mysqlrequiredPeer dependency: provides the underlying MySQL driver and connection logic.
Agent activity
10 hits · last 30 days
node
10
Resources
hi-mysql — npm install hi-mysql · libregistry