如果出现序列化连接错误,如何捕获?
我试着去做
var connection = new Sequelize("db://uri");
connection.on("error", function() { /* perhaps reconnect here */ });但显然这是不受支持的。
我之所以这样做,是因为我认为sequelize可能会偶尔抛出一个未经处理的ETIMEOUT,并使我的节点进程崩溃。
目前我正在使用sequelize连接一个mysql实例。我只需要它大约2-3个小时,在此期间,我将做许多阅读查询。在此期间,mysql服务器将不会连接到任何其他内容。
发布于 2018-03-24 08:03:25
当使用外部迁移或数据库完整性非常重要时,使用sync()是相当危险的(什么时候不是!)
更具up-to-date特色的方法是使用authenticate()
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.');
})
.catch(err => {
console.error('Unable to connect to the database:', err);
});发布于 2016-07-29 12:20:12
为此使用sequelize sync
var Sequelize = require('sequelize');
sequelize = new Sequelize(config.database, config.username, config.password, {
'host' : config.host,
'dialect' : config.dialect,
'port' : config.port,
'logging' : false
})
sequelize.sync().then(function(){
console.log('DB connection sucessful.');
}, function(err){
// catch error here
console.log(err);
});https://stackoverflow.com/questions/38650200
复制相似问题