MariaDB Node.js connector

Non-blocking MariaDB and MySQL client for Node.js.
MariaDB and MySQL client, 100% JavaScript, with TypeScript definition, with the Promise API.
version before 2.4 is compatible with Node.js 6+
version after 2.4 is compatible with Node.js 10+
Documentation
See promise documentation for detailed API.
Callback documentation describe the callback wrapper for compatibility with existing drivers.
See dedicated part for migration from mysql/mysql2 or from 2.x version.
Why a New Client?
While there are existing MySQL clients that work with MariaDB, (such as the mysql
and mysql2
clients), the MariaDB Node.js Connector offers new functionality, like Insert Streaming, Pipelining, ed25519 plugin authentication while making no compromises on performance.
Insert Streaming
Using a Readable stream in your application, you can stream INSERT
statements to MariaDB through the Connector.
https.get('https://someContent', readableStream => {
connection.query("INSERT INTO myTable VALUE (?)", [readableStream]);
});
Pipelining
With Pipelining, the Connector sends commands without waiting for server results, preserving order. For instance, consider the use of executing two INSERT
statements.
The Connector doesn't wait for query results before sending the next INSERT
statement. Instead, it sends queries one after the other, avoiding much of the network latency.
For more information, see the Pipelining documentation.
Bulk insert
Some use cases require a large amount of data to be inserted into a database table. By using batch processing, these queries can be sent to the database in one call, thus improving performance.
For more information, see the Batch documentation.
Benchmarks
MariaDB provides benchmarks comparing the Connector with popular Node.js MySQL clients, including:
query
select * from mysql.user - mysql x 1,442 ops/sec ±0.38%
select * from mysql.user - mysql2 x 1,484 ops/sec ±0.60%
select * from mysql.user - mariadb x 1,595 ops/sec ±0.38%
execute
select * from mysql.user using execute - mysql2 x 2,257 ops/sec ±0.84%
select * from mysql.user using execute - mariadb x 2,651 ops/sec ±0.59%

For more information, see the [Benchmarks](./documentation/benchmarks.md) page.
Quick Start
The MariaDB Connector is available through the Node.js repositories. You can install it using npm :
$ npm install mariadb
example:
const mariadb = require('mariadb');
const pool = mariadb.createPool({host: process.env.DB_HOST, user: process.env.DB_USER, connectionLimit: 5});
async function asyncFunction() {
let conn;
try {
conn = await pool.getConnection();
const rows = await conn.query("SELECT 1 as val");
const res = await conn.query("INSERT INTO myTable value (?, ?)", [1, "mariadb"]);
} finally {
if (conn) conn.release();
}
}
Contributing
If you would like to contribute to the MariaDB Node.js Connector, please follow the instructions given in the Developers Guide.
To file an issue or follow the development, see JIRA.