July 20, 2018

MariaDB Connector/Node.js First Alpha Now Available

MariaDB is pleased to announce the immediate availability of MariaDB Connector/Node.js alpha version 0.7.0. This is a non-blocking MariaDB client for Node.js, 100 percent JavaScript, compatible with Node.js 6+.

Why a new client? While there are existing clients that work with MariaDB, (such as the mysql and mysql2 clients), the MariaDB Node.js Connector offers new functionality, like insert Streaming and Pipelining 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 => {
    //readableStream implement Readable, driver will stream data to database 
    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.

pip - Copie.png

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.

Quick Start

The MariaDB Connector is available through the Node.js repositories. You can install it using npm.

$ npm install mariadb

Using ECMAScript 2017:

const mariadb = require('mariadb');
const pool = mariadb.createPool({host: 'mydb.com', user:'myUser', connectionLimit: 5});

async function asyncFunction() {
  let conn;
  try {
	conn = await pool.getConnection();
	const rows = await conn.query("SELECT 1 as val");
	console.log(rows); //[ {val: 1}, meta: ... ]
	const res = await conn.query("INSERT INTO myTable value (?, ?)", [1, "mariadb"]);
	console.log(res); // { affectedRows: 1, insertId: 1, warningStatus: 0 }

  } catch (err) {
	throw err;
  } finally {
	if (conn) return conn.end();
  }
}


Documentation can be found on the  MariaDB knowledge base and sources are on GitHub.

Benchmarks

Comparing the MariaDB Connector with other Node.js clients:

promise-mysql  : 1,366 ops/sec ±1.42%
mysql2         : 1,469 ops/sec ±1.63%
mariadb        : 1,802 ops/sec ±1.19%

bench.png

Benchmarks for the MariaDB Node.js Connector are done using the popular benchmark.js package. You can find the source code for our benchmarks in the benchmarks/ folder.

Roadmap

The MariaDB Node.js Connector remains in development. This is an alpha release so we do not recommend using it in production. Below is a list of features being developed for future connector releases.

  • PoolCluster
  • MariaDB ed25519 plugin authentication
  • Query Timeouts
  • Bulk Insertion, (that is, fast batch).

Download the MariaDB Node.js Connector directly.

About Diego Dupin

Diego Dupin is a Java senior developer working on MariaDB java connector. 
He like high performance in general, and building great software. 

Read all posts by Diego Dupin