DT
Join ServerDrizzle Team
help
Transaction rollback
Hello guys. Kind of dumb question but should I cover body of transaction in try/catch and call rollback explicitly? Here is an example. What will happen some query throws an error in transaction callback?
sessionId = await db.transaction(async (tx) => {
const [{insertedSessionId}] = await tx
.insert(session)
.values({
auctionid: values.auctionId,
auctiondate: values.auctionDate,
sessiondate: values.previewDate,
})
.returning({insertedSessionId: session.sessionid});
await tx.insert(customersession).values({
sessionid: insertedSessionId,
customerid: values.customerId,
isclone: false,
});
return insertedSessionId;
});
No, the transaction is rolled back automatically
sessionId will be undefined or error will propagate further?
the
await db.transaction
call will throwin other words,
.transaction
will return a rejected Promiseperfect. Maybe it worth to mention this in docs. I didn't find any info about rollback. Thank you!
yes, we're currently working on the proper docs website
thanks for the feedback!
Thanks for awesome library! Have a great weekends)