如何在 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
},
});