phanx-mysql

raw JSON →
0.3.16 verified Sat Apr 25 auth: no javascript maintenance

A MySQL database wrapper for Node.js providing async/await promises, TypeScript definitions, and helper methods for insert/update and named parameters. Current stable version is 0.3.16, last updated with Node.js 11.x support. It wraps the mysql npm package and adds a promise-based interface, automatic idle connection closing, and a query formatter that supports both positional (?) and named (:name) parameters. Unlike more modern libraries (e.g., mysql2, knex), it requires manual configuration via a config.json file and is not actively maintained. It is suitable for simple use cases but lacks connection pooling with advanced features, and the API is somewhat unconventional (e.g., accessing results via getters like db.rows).

error TypeError: PhanxMysql.config is not configurable
cause Attempting to set PhanxMysql.config before import or after connection
fix
Set PhanxMysql.config immediately after import, before any async calls.
error Error: Cannot find module 'config.json'
cause Missing config.json file in the working directory
fix
Create a config.json with database connection info in your project root.
error TypeError: db.query is not a function
cause Using db.query before calling db.start() or createAndStart()
fix
Ensure you await db.start() or await PhanxMysql.createAndStart() before calling query.
gotcha Using require('phanx-mysql') returns the class, not an instance; must call new or use static method createAndStart().
fix Use 'new PhanxMysql()' and then 'await db.start()' or 'await PhanxMysql.createAndStart()'.
deprecated Package is no longer actively maintained; last release 0.3.16 from 2019.
fix Consider migrating to mysql2 or knex for better maintenance and features.
gotcha The config.json file must be present and contain a valid JSON object with connection properties; environment variables are not supported.
fix Create a config.json file in your project root with properties like host, user, password, database.
breaking In version 0.2.x, the API used callbacks; starting 0.3.0 promises were added but the callback style still works.
fix Use async/await or .then() for promise-based control flow.
npm install phanx-mysql
yarn add phanx-mysql
pnpm add phanx-mysql

Shows how to import, configure, create a connection, run a query, and close the connection using async/await.

import PhanxMysql from 'phanx-mysql';
import config from './config.json' with { type: 'json' };

PhanxMysql.config = config;
PhanxMysql.setAutoCloseMinutes(1);

async function run() {
  const db = await PhanxMysql.createAndStart();
  const rows = await db.query('select * from test;');
  if (db.error) console.error(db.error);
  console.log(rows);
  await db.end();
}
run().catch(console.error);