Registry / database / anytv-node-mysql

anytv-node-mysql

JSON →
library1.0.0jsnpmunverified

A MySQL wrapper for Node.js that simplifies database connections, queries, transactions, and pooling with a chainable API. Version 1.0.0, based on the popular node-mysql (mysql npm package) and designed for use with the anyTV Express.js boilerplate. Provides features like automatic connection management, retry on specific errors, auto-reconnect, debugging, squel and knex integration, promise support, and transaction rollback. Differentiators include a key-config registry for multiple databases, elegant transaction handling, and automatic rollback on failure. Maintained but with low activity.

npm install anytv-node-mysql
INSTALL
IMPORT
SIG · ANYTV-NODE-MYSQL
A
anytv-node-mysql
databasejavascriptv1.0.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 mysql from 'anytv-node-mysql'
const mysql = require('anytv-node-mysql')
Default import is the primary entry; CommonJS require works but is not recommended.
mysql.add
mysql.add('db', config)
mysql.setup('db', config) or mysql.create('db', config)
Method to register a database configuration key. No other named exports.
mysql.query
mysql.query('SELECT 1', [], callback).end()
mysql.query('SELECT 1', callback) or mysql.query('SELECT 1', [], callback) without .end()
Query method returns a chainable object; must call .end() to execute and release connection.

Shows registering a database, querying with callback, promise-based query, and a simple transaction.

import mysql from 'anytv-node-mysql'; // Register database config mysql.add('mydb', { host: 'localhost', user: 'root', password: process.env.DB_PASSWORD ?? '', database: 'test' }); // Simple query with callback mysql.query('SELECT ? AS result', ['hello'], (err, rows) => { if (err) console.error(err); else console.log(rows); }).end(); // Promise-based query mysql.build('SELECT ? AS result', ['world']) .promise() .then(rows => console.log(rows)) .catch(err => console.error(err)); // Transaction example mysql.use('mydb') .begin() .query('INSERT INTO users (name) VALUES (?)', ['Alice'], (err, result) => { if (err) throw err; }) .commit() .end();
Debug
Known issues
breakingInterface inconsistency: mysql.query() returns a chainable object without implicit execution; missing .end() will leave connection hanging.
fix
Always chain .end() after query or use .build() + .promise() for promises.
affects: >=1.0.0
gotchaPool connections: to use a pool, pass true as third argument in mysql.add() or mysql.use(); otherwise defaults to single connection.
fix
Use mysql.add('db', config, true) to create a pool, or mysql.use('db', true) to switch to pool.
affects: >=1.0.0
gotchaTransaction automatic rollback: if any query within a transaction fails, the library attempts rollback automatically, but this may mask errors if not handled.
fix
Always check for errors in callbacks or catch rejections; do not rely solely on automatic rollback.
affects: >=1.0.0
gotchasquel and knex integration: When using squel or knex builder objects with .build(), note that the query object must be passed as first argument, not as a string.
fix
Use mysql.build(squelQuery) or mysql.build(knexQuery) directly, not mysql.query(builder).
affects: >=1.0.0
deprecatedNode.js version support: The underlying mysql package is in maintenance mode; consider using mysql2 for newer Node.js versions.
fix
Switch to mysql2 or use a more modern MySQL client like @mysql/xdevapi.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: mysql.add is not a function
Incorrect import: using named import instead of default import.
fix
Use 'import mysql from \'anytv-node-mysql\'' (default import) instead of '{ mysql }' named import.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost'
Missing or incorrect database credentials in config.
fix
Check that config.host, config.user, config.password, and config.database are correct.
Error: connect ECONNREFUSED 127.0.0.1:3306
MySQL server is not running or connection parameters are wrong.
fix
Ensure MySQL server is started and host/port are correct.
TypeError: Cannot read property 'query' of undefined
Calling mysql.query() before registering a database with mysql.add() or mysql.use() without prior add.
fix
Register at least one database configuration using mysql.add() before querying.
Error: Cannot enqueue Handshake after already enqueuing a Handshake.
Attempting to reuse a connection that hasn't been properly closed.
fix
Ensure each query chain ends with .end() to release the connection, or use pool connections.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
mysqlrequiredCore dependency for MySQL database connectivity; anytv-node-mysql wraps mysql's connection, pool, and query functionality.
Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
1
Resources
anytv-node-mysql — npm install anytv-node-mysql · libregistry