当我尝试在事务内回滚时:
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()
}
为什么回滚仅在引发异常时起作用?