Last updated: 2026-10-07
CHAIN YOUR MYSQL QUERIES ACROSS READ AND WRITE POOLS!
A Node.js MySQL connection pool with read-write splitting, a chainable query builder, and slow query logging
npm install @pardnchiu/mysql-pool· Documentation
- Read-Write Split Pools — Maintains separate read and write connection pools, configured from an object or
DB_READ_*/DB_WRITE_*environment variables, with the write side falling back to the read config when omitted. - Chainable Query Builder — Chain select, where, join, orderBy, and limit from
table()throughget(), binding every value through placeholders instead of string concatenation. - Pagination Total in One Query —
total()attaches the full row count via theCOUNT(*) OVER()window function, so paging never needs a second COUNT query. - UPSERT with MySQL Function Allowlist — Values matching allowlisted functions such as
NOW()andUUID()are inlined into SQL while everything else is bound as a parameter. - Slow Query Logging and Graceful Shutdown — Logs the duration and SQL of any query over 20ms and releases both pools automatically on
SIGINT/SIGTERM.
graph TB
App[Application] --> Init["init()"]
Init --> Cfg[Config Resolution<br/>object / env vars]
Cfg --> RP[(Read Pool)]
Cfg --> WP[(Write Pool)]
App --> QB[Chainable Query Builder]
App --> Raw["read() / write()"]
QB --> Exec["query() Executor<br/>slow query log"]
Raw --> Exec
Exec --> RP
Exec --> WP
This project is licensed under the MIT LICENSE.
Just open an issue to share an idea.
©️ 2025 邱敬幃 Pardn Chiu