0

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

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()
}

为什么回滚仅在引发异常时才有效?

4

0 回答 0