Registry / database / async-mysql

async-mysql

JSON →
library1.0.1jsnpmunverified

async-mysql is a lightweight wrapper around the popular mysql npm package that enables async/await syntax for MySQL database operations. Its current stable version is 1.0.1, and it has not seen updates since 2017. The library provides a simple promise-based API, allowing developers to use ES7 async functions instead of callbacks. It is designed for Node.js environments and simplifies connection management and query execution. However, it does not support connection pooling or prepared statements directly, relying on the underlying mysql package for core functionality. The library is considered stable but feature-limited, and alternatives like mysql2 or knex offer more modern features.

npm install async-mysql
INSTALL
IMPORT
SIG · ASYNC-MYSQL
A
async-mysql
databasejavascriptv1.0.1
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 async_mysql from 'async-mysql'
const async_mysql = require('async-mysql')
The library does not export ES modules; CommonJS require is the correct usage.
connect
const connection = await async_mysql.connect({ host: 'localhost' });
const connection = await async_mysql({ host: 'localhost' });
connect is a named function on the default export, not a direct function call.
query
const rows = await connection.query('SELECT 1');
const rows = await connection.query('SELECT 1', callback);
The returned object from connect has a query method that returns a promise; do not pass a callback.

This example shows how to connect to a MySQL database, execute a SELECT query, insert a row with parameterized queries, and fetch all users.

const async_mysql = require('async-mysql'); async function main() { const connection = await async_mysql.connect({ host: 'localhost', user: 'root', password: '', database: 'test' }); const rows = await connection.query('SELECT 1 AS result'); console.log(rows); // [ { result: 1 } ] await connection.query('INSERT INTO users (name) VALUES (?)', ['John']); const users = await connection.query('SELECT * FROM users'); console.log(users); } main().catch(err => console.error(err));
Debug
Known issues
deprecatedNo updates since 2017; consider using mysql2 or knex for active support.
fix
Migrate to mysql2 with promise API or use knex for query building.
affects: all
gotchaThe library does not support connection pooling; each connect call creates a new connection.
fix
Implement your own pool using mysql's createPool or use a different library.
affects: all
gotchaError handling: query errors are thrown as Error objects with MySQL error message, not as custom exceptions.
fix
Wrap queries in try/catch blocks to handle SQL errors appropriately.
affects: all
gotchaParameterized queries use MySQL's ? placeholder; array of values must match placeholder count.
fix
Always provide an array of values for parameterized queries to prevent SQL injection.
affects: all
Errors
Common errors & fixes
TypeError: async_mysql.connect is not a function
The imported async_mysql object is not a module with a connect function due to incorrect import/require.
fix
Use const async_mysql = require('async-mysql'); (CommonJS) or if using ES modules, use a default import workaround.
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'root'@'localhost' (using password: NO)
Connection configuration missing user/password or wrong credentials.
fix
Provide correct host, user, password, and database in the connect configuration object.
ReferenceError: regeneratorRuntime is not defined
The runtime environment does not support async/await natively (older Node.js versions).
fix
Use Node.js 7.6+ or transpile with Babel and include the regenerator-runtime polyfill.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies
mysqlrequiredasync-mysql is a wrapper around the mysql package; it relies on it for all database communication.
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources
async-mysql — npm install async-mysql · libregistry