MariaDB Connector/Node.js 3.0.0-beta Release Notes

Download Release Notes Changelog Connector/Node.js Overview

Release date: 30 Jun 2021

MariaDB Connector/Node.js 3.0.0 is a Beta release.

Do not use beta releases in production!

For an overview of MariaDB Connector/Node.js see the About MariaDB Connector/Node.js page

Notable Changes

Prepared statement implementation

Driver now permits using prepared statement. This methods are compatible with mysql2 with some differences:

  • permit streaming parameters
  • execute use by default a prepared cache that hasn't infinite length (option ‘prepareCacheLength’ with default to 256)
  • Implement mariadb 10.6 new feature, skipping metadata when possible for better performance

New Connection methods:

Example:

const prepare = await conn.prepare('INSERT INTO mytable(id,val) VALUES (?,?)');
await prepare.execute([1, 'val1']);
prepare.close();

Or directly :

await conn.execute('INSERT INTO mytable(id,val) VALUES (?,?)', [1, 'val1']);

If reusing query multiple time, this permits to perform better, specifically using mariadb 10.6. Performance comparison with mysql2 driver show up to 20% performance gain. More info will follow before GA release.

Exact Number implementation

Default behaviour for decoding BIGINT / DECIMAL datatype for 2.x version and mysql/mysql2 drivers return a javascript Number object. BIGINT / DECIMAL values might not be in the safe range, resulting in approximate results.

Since 3.x version, driver has reliable default, returning:

  • DECIMAL => javascript String
  • BIGINT => javascript BigInt object

For compatibility with the previous versions or mysql/mysql driver, 3 options have been added to return BIGINT/DECIMAL as Number, like previous defaults.

OptionDescriptionTypedefault
insertIdAsNumberWhether the query should return last insert id from INSERT/UPDATE command as BigInt or Number. default return BigIntbooleanfalse
decimalAsNumberWhether the query should return decimal as Number. If enabled, this might return approximate values.booleanfalse
bigIntAsNumberWhether the query should return BigInt data type as Number. If enabled, this might return approximate values.booleanfalse

Previous options `supportBigNumbers` and `bigNumberStrings` still exist for compatibility, but are now deprecated.

Custom logging API

Driver permit mapping the logs to an external logger. There is 3 caller functions:

  • network(string): called for each network exchange.
  • query(string): called for each commands
  • error(Error): called for each error.

if setting one function, function will be used for all loggers. (ie. logger: console.log === logger: { network: console.log, query: console.log, error: console.log})

Example:

const mariadb = require('mariadb');
const winston = require('winston');

const logger = winston.createLogger({
  level: 'info',
  transports: [
    // - Write all logs with level `error` and below to `error.log`
    // - Write all logs with level `info` and below to `combined.log`
    new winston.transports.Console({ filename: 'error.log', level: 'error' }),
    new winston.transports.Console({ filename: 'combined.log' })
  ]
});

const pool = mariadb.createPool({
  host: 'mydb.com',
  user:'myUser',
  password: 'myPwd',
  logger: {
    network: (msg) => logger.silly(msg),
    query: (msg) => logger.info(msg),
    error: (err) => logger.error(err),
  }
});

Changelog

For a complete list of changes made in this release, with links to detailed information on each push, see the changelog.

Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.