On Thursday, 17 June 2021 at 20:35:42 UTC, Steven Schveighoffer wrote:
>Does someone know how to do this with current code? Essentially, I want a reentrant transaction that either does commit or rollback whenever the reentrance count goes to 0 and either an exception is being thrown (rollback) or not (commit).
-Steve
I typically add a transaction method to the connection that takes a delegate and executes the delegate in a try catch.
auto transaction(Conn conn, void delegate(Conn) dg) {
conn.begin();
try {
dg(conn);
conn.commit();
} catch (Exception e) {
conn.rollback();
throw e;
}
}