Registry / database / pool-mysql

pool-mysql

JSON →
library2.2.14jsnpmunverified

A MySQL connection pool wrapper with multiple pool support, async/await, connection tagging, and schema-based ORM-like query builder. Latest stable version is 2.2.14, released around 2022. It depends on the mysql package and provides features like writer/reader separation, model definitions with references (one-to-one, one-to-many), and populate queries. Key differentiators include environment-based configuration, priority/limit connection tagging, and a Schema class for defining columns with types like PK, FK, ENUM, Polygon, and DateTime. The library is TypeScript-typed and designed for Node.js, but its activity is low and may lack active maintenance.

npm install pool-mysql
INSTALL
IMPORT
SIG · POOL-MYSQL
P
pool-mysql
databasejavascriptv2.2.14
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 pool from 'pool-mysql'
const pool = require('pool-mysql')
The package exports a default object with query, createPool, connection, Schema etc. In TypeScript, default import works.
Schema
import { Schema } from 'pool-mysql'
import Schema from 'pool-mysql'
Schema is a named export, not default. Also accessible via pool.Schema.
pool.query
pool.query(sql, values, callback)
pool.query(sql, values)
The query method expects a callback; without it, the call will hang or error. Use pool.q for async/await.
pool.createPool
pool.createPool(options)
pool.createPool({ options })
Pass the options object directly, not wrapped in another object. The documentation shows `pool.createPool({ options })` but that's likely a typo; it should be `pool.createPool(options)`.
connection.q
const result = await connection.q(sql, values)
connection.q(sql, values)
q is async, so you must await it or use .then(). Without await, you get a Promise.

Shows three common usage patterns: callback query, async/await with connection.q, and custom pool creation.

import pool from 'pool-mysql'; // Environment config needed: SQL_HOST, SQL_USER, SQL_PASSWORD, SQL_TABLE etc. // Basic query with callback pool.query('SELECT * FROM users WHERE id = ?', [1], (err, data) => { if (err) throw err; console.log(data); }); // Async/await query async function main() { const connection = pool.connection(); try { const result = await connection.q('SELECT * FROM users LIMIT ?', [10]); console.log(result); } catch (err) { console.error(err); } finally { connection.release(); } } main(); // Custom pool const options = { writer: { host: process.env.SQL_HOST_READER || process.env.SQL_HOST }, reader: { host: process.env.SQL_HOST_READER || process.env.SQL_HOST }, forceWriter: false }; const pool2 = pool.createPool(options);
Debug
Known issues
gotchapool.query requires a callback; for async/await use pool.q or connection.q
fix
Use pool.q(sql, values) or connection.q(sql, values) with await
affects: >=1.0
gotchaEnvironment variables must be set (SQL_HOST, SQL_USER, SQL_PASSWORD, SQL_TABLE) or pool will fail
fix
Set required env vars or use dotenv package
affects: >=1.0
deprecatedThe mysql npm package is in maintenance mode; pool-mysql may have similar issues
fix
Consider using mysql2 or other actively maintained drivers
affects: >=1.0
gotchapool.createPool({ options }) in README is misleading; should be pool.createPool(options)
fix
Pass the options object directly, not wrapped in another object
affects: >=2.0
gotchaConnection tagging with limit: if limit is reached, pool will wait indefinitely
fix
Set a timeout or ensure connections are released promptly
affects: >=2.0
breakingNo default export for require in older versions? Check documentation as it may have changed
fix
Use `const pool = require('pool-mysql')` for CJS
affects: <=2.0
Errors
Common errors & fixes
TypeError: pool.query is not a function
Using import incorrectly: import pool from 'pool-mysql' returns an object with query, but if using require('pool-mysql') without default, it may be different.
fix
Ensure import style matches: const pool = require('pool-mysql') for CJS, or import pool from 'pool-mysql' for ESM
Error: Cannot find module 'mysql'
Missing peer dependency mysql
fix
npm install mysql --save
Error: SQL_HOST is not defined
Environment variables not set
fix
Set SQL_HOST, SQL_USER, SQL_PASSWORD, SQL_TABLE in environment or use dotenv
TypeError: pool.query(...) is not a function
Calling pool.query without callback? Actually pool.query is a function, but this error may arise if using pool.q incorrectly.
fix
Use pool.query(sql, values, callback) or pool.q(sql, values) for async
Upgrade
Version history
2.2.14latest on npm
Audit
Dependencies
mysqlrequiredCore dependency for MySQL driver
Agent activity
7 hits · last 30 days
node
6
Resources
pool-mysql — npm install pool-mysql · libregistry