mysql2-async

Standardize MySQL operations with async/await, transactions, and streaming.

1|3|Updated Mar 18, 2020
One-click install
npx skills add https://github.com/txstate-etc/mysql2-async --skill mysql2-async
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mysql2-async
Source: https://github.com/txstate-etc/mysql2-async/tree/main
Command: npx skills add https://github.com/txstate-etc/mysql2-async --skill mysql2-async

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Teams often end up mixing direct mysql2 usage with ad-hoc callback-based patterns, forgetting to manage connection lifecycles, and causing subtle bugs with transactions, streaming, and timezones. This Skill standardizes MySQL access by directing all database operations through a single async/iterable-friendly wrapper.

Core Features & Use Cases

  • Promise-first convenience methods: Use consistent helpers for fetching one row, many rows, single values, or arrays of values.
  • Safe streaming for large result sets: Process rows incrementally with async iteration, with automatic cleanup on break/errors.
  • Transaction-scoped database object: Run related operations on the same connection, with automatic commit/rollback and optional deadlock retries.
  • Parameter binding helpers: Use positional and named parameters, plus an IN helper that mutates binds and produces correct SQL fragments (including tuples and multi-row inserts).
  • UTC timezone handling by default: Ensure consistent storage and retrieval of dates as UTC unless explicitly opting out for legacy schemas.

Use case examples

  • Build a report job that streams millions of rows without exhausting memory.
  • Implement a multi-step business update (select-for-update + update + insert) using a transaction-scoped db object to avoid deadlocks.
  • Create a safe query layer that prevents accidental direct mysql2 usage and keeps all date handling consistent.

Quick Start

Tell the AI: Use mysql2-async to fetch a single row with getrow using a parameterized query and return the typed result.

Frequently Asked Questions about mysql2-async

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle large MySQL result sets with async/await without exhausting memory?

To stream large MySQL result sets safely, process rows incrementally using async iteration. This pattern ensures automatic iterator and connection cleanup when errors occur or when breaking out of the loop, preventing memory exhaustion and connection leaks.

What is the best way to run transactions with async/await in Node.js MySQL?

The best way to run async/await MySQL transactions is by using a transaction-scoped database object. This ensures related operations execute on a single connection with automatic commit or rollback, and you must pass this scoped object into helper functions to maintain consistency.

How do I build safe IN clauses and parameterized queries for MySQL?

Build safe IN clauses by using parameter binding helpers that mutate binds and generate correct SQL fragments. This approach safely handles tuples and multi-row inserts using positional or named parameters without risking SQL injection.

How do I ensure consistent UTC timezone handling with MySQL dates?

Ensure consistent UTC timezone handling by standardizing MySQL access to store and retrieve dates as UTC by default. You only opt out of UTC explicitly when dealing with legacy schemas that require different timezone behavior.

Why should I avoid raw .query() calls and use a preconfigured MySQL pool?

Avoid raw .query() calls to prevent subtle bugs with transactions, streaming, and connection lifecycles. Using a preconfigured database instance or creating a single pool standardizes access, providing promise-first convenience methods for fetching rows and values.