NodeJS pg模块不会在事务内回滚

时间:2019-03-18 00:33:01

标签: node.js postgresql pg pg-node

当我尝试在事务内回滚时:

const client = await pool.connect()
try {
    await client.query('BEGIN')
    const result = await client.query('SELECT...')
    if (result) { await client.query('ROLLBACK') } //DOESN'T WORK
    if (result) { throw new Error() }//WORKS. WHY?
    (...)
    await client.query('COMMIT')
}
catch (e) {
    await client.query('ROLLBACK')
}
finally {
    client.release()
}

为什么回滚仅在引发异常时起作用?

0 个答案:

没有答案