Release Notes for MariaDB Connector/Node.js 3.0.0-RC

Overview

MariaDB Connector/Node.js is a high-performance module for building Node.js applications on top of MariaDB. It provides promise and callback APIs for asynchronous, non-blocking data access as well as pipelining.

MariaDB Connector/Node.js 3.0.0-RC was released on 2021-10-20. It is a Release Candidate (RC) release of MariaDB Connector/Node.js.

Notable Changes

  • Handling and control back pressure for streaming result set (CONJS-168)

    Streaming a result set ensured the connection state before version 3.0, at the cost of not handling back pressure well.

    Since the goal of queryStream is to avoid the use of a large amount of memory, handling of back pressure has been optimized. If data handling takes some amount of time, the socket is paused to avoid the node socket buffer growing indefinitely.

    This has an impact on the use of function stream.pipeline because queryStream now must be closed explicitly to ensure that a connection is not in a wrong state (for example, with unhandled rows in the socket buffer).

    For example:

    const queryStream = connection.queryStream("SELECT * FROM mysql.user");
    stream.pipeline(
       queryStream,
       transformStream,
       someWriterStream,
       (err) => { queryStream.close();
    });
    
  • Optimized defaults (CONJS-176) (CONJS-179)

    The pool cluster option removeNodeErrorCount now defaults to infinity. This prevents a situation where part of the pool is removed from the cluster when a server temporarily fails.

    The pool option resetAfterUse now defaults to false. This avoids the execution of a COM_RESET each time a connection is returned to the pool.

  • New 'stream' option (CONJS-180)

    The option stream provides a way to execute a function with a callback parameter before each connection stream creation.

    Option        Description                                                             Type            Default
    --------------------------------------------------------------------------------------------------------------
    stream        permits to set a function with parameter to set stream (since 3.0)      function
    

    This can permit setting a SSH Tunnel, for example:

    const mariadb = require('mariadb');
    const tunnel = require('tunnel-ssh');
    const fs = require('fs');
    
    const conn = await mariadb.createConnection({
       user: 'dbuser',
       password: 'dbpwd',
       port: 27000,
       stream: (cb) =>
         tunnel(
           {
             // remote connection ssh info
             username: 'sshuser',
             host: '157.230.123.7',
             port: 22,
             privateKey: fs.readFileSync('./key.ppk'),
             // database (here on ssh server)
             dstHost: '127.0.0.1',
             dstPort: 3306,
             // local interface
             localHost: '127.0.0.1',
             localPort: 27000
           },
           cb
         )
     });
    

Other Optimizations

  • Batch operations now support the returning clause (CONJS-125)

    • For example: INSERT INTO XXX VALUES (?,?,?) RETURNING id

  • Update code to Ecma version ES2022 supported by Node.js 12 (CONJS-178)

  • Performance improvement for multi-line result sets (CONJS-172)

Installation