Back to Sequelize

MariaDB

docs/databases/mariadb.mdx

latest18.8 KB
Original Source

Sequelize for MariaDB

:::info Version Compatibility

See Releases to see which versions of MariaDB are supported.

:::

To use Sequelize with MariaDB, you need to install the @sequelize/mariadb dialect package:

bash
npm i @sequelize/mariadb

Then use the MariaDbDialect class as the dialect option in the Sequelize constructor:

ts
import { Sequelize } from '@sequelize/core';
import { MariaDbDialect } from '@sequelize/mariadb';

const sequelize = new Sequelize({
  dialect: MariaDbDialect,
  database: 'mydb',
  user: 'myuser',
  password: 'mypass',
  host: 'localhost',
  port: 3306,
  showWarnings: true,
  connectTimeout: 1000,
});

Connection Options

import ConnectionOptions from './_connection-options.md';

<ConnectionOptions />

The following options are passed as-is to the mariadb package that Sequelize uses to connect to MariaDB. Please refer to the MariaDB documentation for more information about what each of these options do.

For convenience, here is an edited copy of the documentation that only includes the options that are accepted by Sequelize:

OptionDescriptionTypeDefault
userUser to access databasestring
passwordUser passwordstring
hostIP address or DNS of database server. Not used when using the socketPath optionstring"localhost"
portDatabase server port numberinteger3306
databaseDefault database to use when establishing the connectionstring
socketPathPermit connecting to the database via Unix domain socket or named pipe, if the server allows itstring
compressCompress exchanges with database using gzip. This can give you better performance when accessing a database in a different location.booleanfalse
connectTimeoutConnection timeout in millisecondsinteger1000
socketTimeoutSocket timeout in milliseconds after the connection is establishedinteger0
maxAllowedPacketpermit to indicate server global variable max_allowed_packet value to ensure efficient batching. default is 4Mb. see batch documentationinteger4196304
prepareCacheLengthDefine prepare LRU cache length. 0 means no cacheint256
sslSSL options. See SSL options in the MariaDB documentationboolean | objectfalse
charsetProtocol character set used with the server. Connection collation will be the default collation associated with charset. It's mainly used for micro-optimizations. The default is often sufficient.stringUTF8MB4
collation(used in replacement of charset) Permit to defined collation used for connection. This will defined the charset encoding used for exchanges with database and defines the order used when comparing strings. It's mainly used for micro-optimizationsstringUTF8MB4_UNICODE_CI
debugLogs all exchanges with the server. Displays in hexa.booleanfalse
debugLenString length of logged message / error or traceinteger256
logParamindicate if parameters must be logged by query logger.booleanfalse
foundRowsWhen enabled, the update number corresponds to update rows. When disabled, it indicates the real rows changed.booleantrue
multipleStatementsAllows you to issue several SQL statements in a single query() call. (That is, INSERT INTO a VALUES('b'); INSERT INTO c VALUES('d');).

This may be a security risk as it allows for SQL Injection attacks. | boolean | false | | permitLocalInfile | Allows the use of LOAD DATA INFILE statements.

Loading data from a file from the client may be a security issue, as a man-in-the-middle proxy server can change the actual file the server loads. Being able to execute a query on the client gives you access to files on the client. | boolean | false | | pipelining | Sends queries one by one without waiting on the results of the previous entry. For more information, see Pipelining( | boolean | true | | trace | Adds the stack trace at the time of query creation to the error stack trace, making it easier to identify the part of the code that issued the query. Note: This feature is disabled by default due to the performance cost of stack creation. Only turn it on when you need to debug issues. | boolean | false | | connectAttributes | Sends information, (client name, version, operating system, Node.js version, and so on) to the Performance Schema. When enabled, the Connector sends JSON attributes in addition to the defaults. | boolean | object | false | | sessionVariables | Permit to set session variables when connecting. Example: sessionVariables: { idle_transaction_timeout: 10000 } | object | | initSql | When a connection is established, permit to execute commands before using connection | string | array | | bulk | disabled bulk command in batch | boolean | | forceVersionCheck | Force server version check by explicitly using SELECT VERSION(), not relying on server initial packet. | boolean | false | | checkDuplicate | Indicate to throw an exception if result-set will not contain some data due to having duplicate identifier. JSON cannot have multiple identical key, so query like SELECT 1 as i, 2 as i cannot result in { i:1, i:2 }, 'i:1' would be skipped. When checkDuplicate is enable (default) driver will throw an error if some data are skipped. | boolean | true | | keepAliveDelay | permit to enable socket keep alive, setting delay. 0 means not enabled. Keep in mind that this don't reset server @@wait_timeout (use pool option idleTimeout for that). in ms | integer | | | rsaPublicKey | Indicate path/content to MySQL server RSA public key. | string | | | cachingRsaPublicKey | Indicate path/content to MySQL server caching RSA public key. | string | | | allowPublicKeyRetrieval | Indicate that if rsaPublicKey or cachingRsaPublicKey public key are not provided, if client can ask server to send public key. | boolean | false | | stream | permits to set a function with parameter to set stream | function | | | metaEnumerable | make resultset meta property enumerable | boolean | false | | infileStreamFactory | When LOAD LOCAL command executed, permit to set a callback function of type (filepath?: string) => stream.Readable. Connector will then not send file from LOAD LOCAL, but Readable content. This can permit to set extra validation of file path for example. | function | | | logPackets | Debug option : permit to save last exchanged packet. Error messages will display those last exchanged packet. | boolean | false | | debugCompress | This will print all incoming and outgoing compressed packets on stdout. | boolean | false | | queryTimeout | Command execution timeout | number | |

Other MariaDB Options

The following options are also available for MariaDB:

OptionDescription
showWarningsIf true, warnings produced during the execution of a query will be sent to the logging callback. Default is false.