Registry / database / k9-mysql

k9-mysql

JSON →
library1.0.2jsnpmunverified

A Node.js MySQL driver that exclusively supports connection pools and generator-based (co) asynchronous flow with transaction support. Version 1.0.2 is stable with no recent updates. It provides a simple API around pool initialization, queries, transactions, and rollbacks. Unlike mysql2 or knex, it uses yield/co patterns and requires global pool initialization before any query. It is minimal and opinionated, making it suitable for legacy generator-based Node.js projects.

npm install k9-mysql
INSTALL
IMPORT
SIG · K9-MYSQL
K
k9-mysql
databasejavascriptv1.0.2
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.

initmysqlpool
const { initmysqlpool } = require('k9-mysql');
import { initmysqlpool } from 'k9-mysql';
This package is CJS-only; ES imports are not supported.
query
const { query } = require('k9-mysql');
const query = require('k9-mysql').query;
Both styles work, but destructuring is preferred.
getConnection
const { getConnection } = require('k9-mysql');
import getConnection from 'k9-mysql';
Must be destructured from the module export.

Initializes a MySQL connection pool and runs a simple SELECT query using the generator-style API wrapped in async/await.

const { initmysqlpool, query } = require('k9-mysql'); initmysqlpool({ user: process.env.MYSQL_USER ?? 'root', password: process.env.MYSQL_PASSWORD ?? '', host: process.env.MYSQL_HOST ?? 'localhost', port: parseInt(process.env.MYSQL_PORT ?? '3306'), database: process.env.MYSQL_DATABASE ?? 'test', options: { poolMax: 2, poolAlias: 'myPool', retry_interval: 60, poolTimeout: 5000, poolDelay: 5000, isPooled: false, timezone: '0800' } }); async function runQuery() { try { const rows = await query('SELECT 1 + 1 AS solution', null); console.log('Result:', rows); } catch (err) { console.error(err); } } runQuery();
Debug
Known issues
gotchaPackage only supports connection pool mode; single connections are not available.
fix
Use initmysqlpool before any query operation.
affects: >=1.0.0
gotchaAll query functions expect to be called with yield (co) or must be wrapped in a promise; they do not return promises directly.
fix
Wrap calls in a co generator or promisify them.
affects: >=1.0.0
gotchaThe library is CJS-only and does not support ESM imports.
fix
Use require() instead of import.
affects: >=1.0.0
gotchaMust call initmysqlpool exactly once before any other operation; calling it multiple times may cause undefined behavior.
fix
Initialize pool at application startup.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: initmysqlpool is not a function
Incorrect import style (ESM import on CJS module).
fix
Use const { initmysqlpool } = require('k9-mysql');
Error: Cannot find module 'mysql'
Missing peer dependency 'mysql'.
fix
Run npm install mysql
TypeError: pool.query is not a function
Pool not initialized or query called before initmysqlpool.
fix
Ensure initmysqlpool is called first with valid options.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
mysqlrequiredk9-mysql wraps the mysql package for pool and connection management
cooptionalRequired for using generator-based yield syntax in query examples
Agent activity
9 hits · last 30 days
node
8
Resources
k9-mysql — npm install k9-mysql · libregistry