333910
项目中每天会去请求数据库查询数据,用到了事务来创建临时表,第一次查询的时候没问题,第二次查询的时候报错表格已建立,以下是代码。
async handler() {
this.connection = await this.pMysql.getConnection()
await this.connection.beginTransaction()
try {
const limit = pLimit(10) // p-limit库
let promise = []
promise.push(limit(() => this.doSomething1()))
promise.push(limit(() => this.doSomething2()))
promise.push(limit(() => this.doSomething3()))
promise.push(limit(() => this.doSomething4()))
// ...
await Promise.all(promise)
await this.connection.commit()
await this.connection.release()
} catch (e) {
await this.connection.rollback()
await this.connection.release()
throw e
}
}
问题可以通过删除表来解决。但我想知道为什么第二次创建临时表会报错?临时表不是和connection的生命周期绑定的吗?