我一直在检查MariaDB与Sequelize的连通性。
const Sequelize = require('sequelize');
// Setting up database (MariaDB) connection
const sequelize = new Sequelize('dbName', 'usr', 'pass', {
host: 'localhost',
dialect: 'mariadb'
});
但是我遇到以下错误:
/home/lt-196/api/node_modules/sequelize/lib/sequelize.js:236
throw new Error('The dialect ' + this.getDialect() + ' is not supported. Supported dialects: mssql, mysql, postgres, and sqlite.');
^
Error: The dialect mariadb is not supported. Supported dialects: mssql, mysql, postgres, and sqlite.
at new Sequelize (/home/lt-196/api/node_modules/sequelize/lib/sequelize.js:236:15)
at Object.<anonymous> (/home/lt-196/api/app.js:21:19)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:191:16)
at bootstrap_node.js:612:3
答案 0 :(得分:1)
MariaDB 为了与MariaDB兼容,您必须安装软件包mariasql@0.1.20或更高版本。 配置需要如下所示:
var sequelize = new Sequelize('database', 'username', 'password', {
dialect: 'mariadb'
})
或尝试以下操作:
MariaSQL:https://www.npmjs.com/package/mariasql
绑定到MariaDB非阻塞(与MySQL兼容)客户端库的node.js。
var Client = require('mariasql');
var c = new Client({
host: '127.0.0.1',
user: 'foo',
password: 'bar'
});
c.query('SHOW DATABASES', function(err, rows) {
if (err)
throw err;
console.dir(rows);
});
c.end();
推荐使用MariaSQL。
答案 1 :(得分:0)
这就是您想要的,它于2018年12月发布。ProperSequelize版本和MariaDB连接。
npm install --save mariadb
npm install --save sequelize@next
--- or ---
yarn add mariadb
yarn add sequelize@next
设置您的Sequelize连接dialect: 'mariadb'
此NodeJS连接器直接从MariaDB发货。 https://github.com/MariaDB/mariadb-connector-nodejs
此连接器比mysql2快得多。 MariaDB提供了与此连接器进行比较的基准:promise-mysql,mysql,mysql2
promise-mysql : 1,366 ops/sec ±1.42%
mysql2 : 1,469 ops/sec ±1.63%
mariadb : 1,802 ops/sec ±1.19%