Skip to content
MariaDB Connector/Node.js is used to connect applications developed on Node.js to MariaDB and MySQL databases. MariaDB Connector/Node.js is LGPL licensed.
Branch: master
Clone or download
rusher
Latest commit d068ce5 Jul 19, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis [misc] maxscale testing 10 4 bases Jul 10, 2019
benchmarks [CONJS-89] Performance improvement on decoding string Jul 10, 2019
documentation [misc] benchmark result charset correction Jul 15, 2019
lib [CONJS-57] correcting multi-authentication in compress mode Jul 11, 2019
test [misc] updating test for 10.4 possible default cipher and mysql non a… Jul 19, 2019
tools [misc] changed max line length to 100 Jul 9, 2019
types [misc] changed max line length to 100 Jul 9, 2019
.eslintrc test linefeed for windows Mar 22, 2019
.gitignore add yarn.lock into gitigngore Dec 19, 2018
.prettierrc [misc] changed max line length to 100 Jul 9, 2019
.travis.yml [misc] testing base server 10.4 Jul 9, 2019
LICENSE [misc] adding LGPL2.1+ license file Dec 12, 2018
README.md [misc] updating benchmarks results for 2.1.0 Jul 12, 2019
appveyor.yml [misc] testing base server 10.4 Jul 9, 2019
azure-pipelines.yml [MENT-29] azure CI install ubuntu from tar Jul 18, 2019
callback.js [CONJS-70] Pool improvement small rewrite for better separation in pr… May 3, 2019
package.json bump 2.1.0 version Jul 11, 2019
promise.js

README.md

MariaDB Node.js connector

Linux Build Windows status License (LGPL version 2.1) codecov

Non-blocking MariaDB and MySQL client for Node.js.

MariaDB and MySQL client, 100% JavaScript, with TypeScript definition, compatible with Node.js 6+, with the Promise API.

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 => {
        //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.

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:

promise-mysql  : 646 ops/sec ±2.20%
mysql2         : 746 ops/sec ±2.35%
mariadb        : 961 ops/sec ±2.82%

query: SELECT < all mysql fields >, 1 FROM mysql.user LIMIT 1

For more information, see the Benchmarks page.

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});
pool.getConnection()
    .then(conn => {
    
      conn.query("SELECT 1 as val")
        .then((rows) => {
          console.log(rows); //[ {val: 1}, meta: ... ]
          return conn.query("INSERT INTO myTable value (?, ?)", [1, "mariadb"]);
        })
        .then((res) => {
          console.log(res); // { affectedRows: 1, insertId: 1, warningStatus: 0 }
          conn.end();
        })
        .catch(err => {
          //handle error
          conn.end();
        })
        
    }).catch(err => {
      //not connected
    });

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

The MariaDB Node.js Connector can use different APIs on the back-end: Promise and Callback.
The default API is Promise API.

Callback API is provided for compatibility with the mysql and mysql2 APIs.

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.

You can’t perform that action at this time.