Files
payload/packages/db-postgres/src/transactions/rollbackTransaction.ts
2023-11-08 12:38:25 -05:00

18 lines
575 B
TypeScript

import type { RollbackTransaction } from 'payload/database'
export const rollbackTransaction: RollbackTransaction = async function rollbackTransaction(
id = '',
) {
// if multiple operations are using the same transaction, the first will flow through and delete the session.
// subsequent calls should be ignored.
if (!this.sessions[id]) {
return
}
// end the session promise in failure by calling reject
await this.sessions[id].reject()
// delete the session causing any other operations with the same transaction to fail
delete this.sessions[id]
}