如何在 Sequelize 中设置查询超时? [英] How to set query timeout in Sequelize?
本文介绍了如何在 Sequelize 中设置查询超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想看看如何在 Sequelize 中设置查询的超时时间.
I'm looking to see how one can set the timeout time of queries in Sequelize.
我已经查看了 Sequelize 文档以获取一些信息,但我无法完全找到我正在寻找的内容.我发现的最接近的是pools.acquire"选项,但我不想设置传入连接的超时,而是设置正在进行的查询的超时,以便我可以快速短路死锁.
I've looked into the Sequelize docs for some info but I can't quite find what I'm looking for. The closest I have found is the "pools.acquire" option, but I'm not looking to set the timeout for an incoming connection, but rather the timeout of an ongoing query so that I may short-circuit deadlocks quickly.
http://docs.sequelizejs.com/class/lib/sequelize.js~Sequelize.html
这是我的示例代码:
const db = new Sequelize( database, username, password, {
host : hostname,
dialect: "mysql",
define : {},
pool: {
max : 10,
min : 0,
idle: 10000
},
})
任何见解将不胜感激!
推荐答案
add dialectOptions
const db2 = new Sequelize(database, username, password, {
host: hostname,
dialect: "mysql",
define: {},
dialectOptions: {
options: {
requestTimeout: 3000
}
},
pool: {
max: 10,
min: 0,
idle: 10000
},
});
这篇关于如何在 Sequelize 中设置查询超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文