mariadb与sequelize的连接

x759pob2  于 2021-06-20  发布在  Mysql
关注(0)|答案(2)|浏览(528)

我一直在检查mariadb和sequelize的连接。

  1. const Sequelize = require('sequelize');
  2. // Setting up database (MariaDB) connection
  3. const sequelize = new Sequelize('dbName', 'usr', 'pass', {
  4. host: 'localhost',
  5. dialect: 'mariadb'
  6. });

但我得到以下错误:

  1. /home/lt-196/api/node_modules/sequelize/lib/sequelize.js:236
  2. throw new Error('The dialect ' + this.getDialect() + ' is not supported. Supported dialects: mssql, mysql, postgres, and sqlite.');
  3. ^
  4. Error: The dialect mariadb is not supported. Supported dialects: mssql, mysql, postgres, and sqlite.
  5. at new Sequelize (/home/lt-196/api/node_modules/sequelize/lib/sequelize.js:236:15)
  6. at Object.<anonymous> (/home/lt-196/api/app.js:21:19)
  7. at Module._compile (module.js:652:30)
  8. at Object.Module._extensions..js (module.js:663:10)
  9. at Module.load (module.js:565:32)
  10. at tryModuleLoad (module.js:505:12)
  11. at Function.Module._load (module.js:497:3)
  12. at Function.Module.runMain (module.js:693:10)
  13. at startup (bootstrap_node.js:191:16)
  14. at bootstrap_node.js:612:3
kx1ctssn

kx1ctssn1#

mariadb为了与mariadb兼容,您必须安装软件包mariasql@0.1.20,或更高。配置需要如下所示:

  1. var sequelize = new Sequelize('database', 'username', 'password', {
  2. dialect: 'mariadb'
  3. })

或者试试这个:
mariasql公司:https://www.npmjs.com/package/mariasql
绑定到mariadb的非阻塞(mysql兼容)客户端库的node.js。

  1. var Client = require('mariasql');
  2. var c = new Client({
  3. host: '127.0.0.1',
  4. user: 'foo',
  5. password: 'bar'
  6. });
  7. c.query('SHOW DATABASES', function(err, rows) {
  8. if (err)
  9. throw err;
  10. console.dir(rows);
  11. });
  12. c.end();

建议使用mariasql。

展开查看全部
jecbmhm3

jecbmhm32#

https://github.com/mariadb/mariadb-connector-nodejs
npm公司

  1. npm install --save mariadb
  2. npm install --save sequelize@next

Yarn

  1. yarn add mariadb
  2. yarn add sequelize@next
  1. const Sequelize = require('sequelize'),
  2. sequelize = new Sequelize(process.env.db_name, process.env.db_user, process.env.db_pass, {
  3. dialect: 'mariadb',
  4. dialectOptions: {
  5. socketPath: process.env.db_socket,
  6. timezone: process.env.db_timezone
  7. },
  8. pool: {
  9. min: 0,
  10. max: 5,
  11. idle: 10000
  12. },
  13. define: {
  14. charset: 'utf8',
  15. timestamps: false
  16. },
  17. benchmark: false,
  18. logging: false
  19. })
展开查看全部

相关问题