mariadb-connector-nodejs-usage

Guides writing Node.js application code against MariaDB using the mariadb npm driver.

28|115|Updated Jan 28, 2025
One-click install
npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-connector-nodejs-usage-mariadb-corporation
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: mariadb-connector-nodejs-usage
Source: https://github.com/mariadb-corporation/mariadb-docs/tree/main/agent-skills/granular/connectors/mariadb-connector-nodejs-usage
Command: npx skills add https://github.com/mariadb-corporation/mariadb-docs --skill mariadb-connector-nodejs-usage-mariadb-corporation

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Generated Node.js database code often carries habits from mysql/mysql2 or other DB-API drivers that break or misbehave with MariaDB Connector/Node.js, such as wrong placeholder styles, mishandled BigInt values, unbuffered memory blowups, and leaked pool connections. ## Core Features & Use Cases - API and placeholder rules: Covers the Promise API as default, the Callback API at require('mariadb/callback'), positional ? placeholders, and the namedPlaceholders option for :name syntax. - Type and result handling: Explains BigInt defaults for BIGINT and insertId, result-set shapes for SELECT versus INSERT/UPDATE/DELETE, and multi-result arrays from CALL. - Performance and resource patterns: Details batch() bulk inserts, queryStream() for large results, pool.getConnection() with release() in finally, explicit transactions, and prepared statement caching with execute() and prepare(). - Use Case: When reviewing a Node.js service that loops query() calls for bulk inserts and never releases pooled connections, apply this Skill to rewrite it with batch() and a try/finally release pattern. ## Quick Start Ask the AI to write or review Node.js code that connects to MariaDB with the mariadb npm package, such as a pooled transaction or a bulk insert.

Frequently Asked Questions about mariadb-connector-nodejs-usage

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

FAQPage Schema
How do I use the MariaDB Node.js driver with async/await?▼

The mariadb npm package defaults to a Promise API, so import mariadb from 'mariadb' and await calls like pool.query(). The Callback API is a separate entry point at require('mariadb/callback').

How to do bulk inserts with MariaDB Connector/Node.js?▼

Use conn.batch(sql, arrayOfArrays) instead of looping query() calls. On MariaDB 10.2.7 and later it uses the COM_STMT_BULK_EXECUTE protocol in a single round trip, with automatic fallback on older servers.

MariaDB Node.js vs mysql2 driver, what is different?▼

The mariadb package defaults to the Promise API, uses ? positional placeholders (named placeholders need the namedPlaceholders option), does not support ?? identifier escaping, and returns insertId and BIGINT as native BigInt by default.

Why does insertId return a BigInt in Node.js MariaDB queries?▼

The connector returns insertId and BIGINT columns as native BigInt so values above 2^53 stay exact. Set insertIdAsNumber or bigIntAsNumber to get plain Numbers when values stay within the safe integer range.

How do I stream large query results in Node.js with MariaDB?▼

Use conn.queryStream(sql, values), since query() buffers the entire result set in memory. Consume the stream with for await or data/error/end events, and call stream.close() if row handling throws mid-stream.

Why does my MariaDB Node.js pool stop responding under load?▼

Connections from pool.getConnection() must be returned with conn.release() in a finally block, or the pool exhausts its default connectionLimit of 10. Prefer pool.query() and pool.batch(), which auto-acquire and auto-release.