Upgrade from MariaDB Connector/Node.js 2.5 to 3.4

Overview

When upgrading from MariaDB Connector/Node.js 2.5 to 3.4, application code must be updated to reflect changes in connector behavior.

Time Zone Conversions

  • Starting with MariaDB Connector/Node.js 3.1, instead of performing time zone conversions locally, MariaDB Connector/Node.js can set the session value of the time_zone system variable. This allows the remote server to handle time zone conversions. In previous releases, time zone conversions are performed locally.

Load tzdata into MariaDB Enterprise Server

To load tzdata into MariaDB Server, use the mariadb-tzinfo-to-sql utility:

$ mariadb-tzinfo-to-sql /usr/share/zoneinfo | mariadb -u root mysql

timezone Parameter Changes

  • Starting with MariaDB Connector/Node.js 3.1, all time zone conversions are performed on the remote server. The timezone parameter is used to configure the behavior. The arguments have not changed, but the meaning of each argument has changed slightly:

    timezone
    (Parameter Argument)

    Description

    local

    • This is the default mode.

    • The session value of the time_zone system variable is not set, so no time zone conversion is performed.

    • This mode is only recommended when the client and server use the same time zone.

    auto

    • If the server's time zone is different from the client's time zone, the session value of the time_zone system variable is set to the client's time zone.

    • This mode is recommended when the server and client use different time zones, but the client's time zone is known to be properly configured.

    • If the client's time zone is set to an IANA time zone name and the remote server is MariaDB Server, the time zone database must be loaded on the remote server. MariaDB Server only supports IANA time zone names in the time_zone system variable when the data from the IANA time zone database (also known as tzdata or zoneinfo) has been loaded using the mariadb-tzinfo-to-sql utility.

    IANA time zone name
    (such as America/New_York)
    • The session value of the time_zone system variable is set to the provided IANA time zone name without checking the server's time zone.

    • If the remote server is MariaDB Server, the time zone database must be loaded on the remote server. MariaDB Server only supports IANA time zone names in the time_zone system variable when the data from the IANA time zone database (also known as tzdata or zoneinfo) has been loaded using the mariadb-tzinfo-to-sql utility.

    UTC offset
    (such as -04:00)
    • The session value of the time_zone system variable is set to the provided UTC offset without checking the server's time zone.

TypeScript

  • Starting with MariaDB Connector/Node.js 3.1, with TypeScript, the batch(), execute(), and query() methods have been internally defined to have type assertions, so that applications can assign the return values without defining type assertion at the application level.

    • In previous releases, assigning the return values of the batch(), execute(), and query() methods required type assertions, which means the METHOD_CALL() AS TYPE_NAME or <TYPE_NAME> METHOD_CALL() syntax was required.

    • Starting with MariaDB Connector/Node.js 3.1, the type assertions are defined internally using generic types.

Exact Decoding for BIGINT and DECIMAL

The default behavior for MariaDB Connector/Node.js 2.5 (and for other existing drivers like mysql2) for decoding the data types BIGINTBIGINT and DECIMALDECIMAL is to return a JavaScript Number object. JavaScript uses double-precision floating-point format numbers as specified in IEEE 754, which is returning approximate results for big values.

Integers can only be safely represented between -(2^53 - 1) and 2^53 - 1.

MariaDB Connector/Node.js, to return precise values, by default returns the objects:

  • DECIMAL => JavaScript String object

  • BIGINT => JavaScript BIGINTBIGINT

For compatibility reasons three options have been added to return BIGINT / DECIMAL as a number object:

Options

Description

Type

Default

insertIdAsNumber

Whether the query should return the last insert id from INSERT/UPDATE command as BigInt or NUMBER. Default return BigInt

boolean

false

decimalAsNumber

Whether the query should return decimal as NUMBER. If enabled, this might return approximate values.

boolean

false

bigIntAsNumber

Whether the query should return BigInt data type as NUMBER. If enabled, this might return approximate values.

boolean

false

checkNumberRange

Used in conjunction with decimalAsNumber, insertIdAsNumber or bigIntAsNumber to determine if an error should be raised when a value can't be converted to a number without losing precision.

boolean

false

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

Custom Logging API

External logging can now be easily enabled using the logging API, provided with MariaDB Connector/Node.js via the three caller functions:

  • network(string): called for each network exchange.

  • query(string): called for each command.

  • error(Error): called for each error.

Simple example to log network exchanges, queries, and errors:

const pool = mariadb.createPool({
  host: 'example.com',
  user:'myUser',
  password: 'myPwd',
  logger: (msg) => console.log(msg)
});

Example of a more detailed use:

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: 'example.com',
  user: 'myUser',
  password: 'myPwd',
  logger: {
    query: (msg) => logger.info(msg),
    error: (err) => logger.error(err),
  }
});

Options

Changes to Default Values

Option

Old Default Value

New Default Value

removeNodeErrorCount

5

Infinity

resetAfterUse

true

false

metaEnumerable

true

false

New Options

Option

Description

Data Type

Default Value

stream

permits to set a function with parameter to set stream

function

null

insertIdAsNumber

Whether the query should return the last insert id from INSERT/UPDATE command as BigInt or NUMBER. Default is to return BigInt

boolean

false

decimalAsNumber

Whether the query should return decimal as NUMBER. If enabled, this might return approximate values.

boolean

false

bigIntAsNumber

Whether the query should return BigInt data type as NUMBER. If enabled, this might return approximate values.

boolean

false

checkNumberRange

Used in conjunction with decimalAsNumber, insertIdAsNumber or bigIntAsNumber to determine if an error should be raised when a value can't be converted to a number without losing precision.

boolean

false

Deprecated Options

Deprecated Option

Upgrade Guidance

supportBigNumbers

BigInt is now supported. Applications must use BigInt compared to using the external Long package.

bigNumberStrings

BigInt is now supported. Applications must use BigInt compared to using String value for a big number.