mariadb与sequelize的连接

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

我一直在检查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
kx1ctssn

kx1ctssn1#

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。

jecbmhm3

jecbmhm32#

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

npm install --save mariadb
    npm install --save sequelize@next

Yarn

yarn add mariadb
    yarn add sequelize@next
const Sequelize = require('sequelize'),
    sequelize = new Sequelize(process.env.db_name, process.env.db_user, process.env.db_pass, {
    dialect: 'mariadb',
    dialectOptions: {
      socketPath: process.env.db_socket,
      timezone: process.env.db_timezone
    },
    pool: {
      min: 0,
      max: 5,
      idle: 10000
    },
    define: {
      charset: 'utf8',
      timestamps: false
    },
    benchmark: false,
    logging: false
  })

相关问题