gpt4 book ai didi

javascript - MariaDB 与 Sequelize 的连接

转载 作者:行者123 更新时间:2023-11-29 02:41:12 24 4
gpt4 key购买 nike

我一直在使用 Sequelize 检查 MariaDB 的连接性。

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

最佳答案

玛丽亚数据库为了与 MariaDB 兼容,您必须安装包 mariasql@0.1.20 或更高版本。配置需要如下所示:

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

或者试试这个:

MariaSQL:https://www.npmjs.com/package/mariasql

绑定(bind)到 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。

关于javascript - MariaDB 与 Sequelize 的连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51653620/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com