Registry / database / mysql-promisify-pool

mysql-promisify-pool

JSON →
library2.1.0jsnpmunverified

A lightweight wrapper around the mysql npm package that provides Promise-based async/await support for MySQL connection pools. Version 2.1.0 is the current stable release, ships TypeScript definitions, and uses environment variables for configuration via DB_HOST, DB_USER, DB_PW, and DB_NAME. It leverages the mysql.Pool.getConnection method to reuse existing connections. Compared to alternatives like mysql2/promise, this package is a simple promisification layer without advanced features like prepared statements or query streaming.

npm install mysql-promisify-pool
INSTALL
IMPORT
SIG · MYSQL-PROMISIFY-PO
M
mysql-promisify-pool
databasejavascriptv2.1.0
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 'mysql-promisify-pool'
const pool = require('mysql-promisify-pool')
ESM default import; CommonJS require also works but TS may require esModuleInterop
query
import { query } from 'mysql-promisify-pool'
import query from 'mysql-promisify-pool'
Named export for single query function; default export is the pool object
Pool
import { Pool } from 'mysql-promisify-pool'
import Pool from 'mysql-promisify-pool'
TypeScript type export; not a runtime value

Shows ESM import, environment variable setup with dotenv, and async query execution with error handling.

// Ensure environment variables are set: DB_HOST, DB_USER, DB_PW, DB_NAME import dotenv from 'dotenv'; dotenv.config(); import pool from 'mysql-promisify-pool'; const fetchUsers = async () => { try { const rows = await pool.query('SELECT * FROM users'); console.log(rows); } catch (error) { console.error('Query failed:', error); } }; fetchUsers();
Debug
Known issues
gotchaEnvironment variables must be set before importing the package, otherwise it throws silently.
fix
Load dotenv.config() at the very beginning of your entry file before any other imports.
affects: >=2.0.0
breakingIn version 2.0.0, the API changed from exporting a class to exporting a pool instance directly.
fix
Use default import as shown; stop using `new Pool()` or `Pool.query()`. Check migration guide.
affects: >=2.0.0
deprecatedThe package does not support connection release; it relies on mysql pool's automatic release, which may cause issues in high concurrency.
fix
Consider using `getConnection` from the pool directly if you need manual release, or switch to mysql2/promise.
affects: all
gotchaTypeScript types are exported but may not fully align with runtime behavior for custom queries.
fix
Cast query result as needed: `const result = await pool.query(sql) as MyType[]`.
affects: >=2.0.0
breakingThe package switched from callback-based to Promise-based API, breaking existing callback usage.
fix
Use async/await or .then()/.catch() instead of callbacks.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'mysql-promisify-pool'
Package not installed or not in node_modules.
fix
Run `npm install mysql-promisify-pool` and ensure your package.json includes it.
TypeError: pool.query is not a function
Incorrect import style (e.g., `import { query } from 'mysql-promisify-pool'` but pool is the default export).
fix
Use `import pool from 'mysql-promisify-pool'` for default import.
Error: Pool.query: Environment variable DB_HOST not set
Missing required environment variables before module initialization.
fix
Set DB_HOST, DB_USER, DB_PW, DB_NAME in your environment or .env file and load dotenv first.
Upgrade
Version history
2.1.0latest on npm
Audit
Dependencies
mysqlrequiredCore MySQL driver used for underlying connection pool and query execution
Agent activity
2 hits · last 30 days
node
2
Resources
mysql-promisify-pool — npm install mysql-promisify-pool · libregistry