github.com/mitranim/gg@v0.1.17/gsql/gsql_misc.go (about) 1 package gsql 2 3 import "github.com/mitranim/gg" 4 5 /* 6 Must be deferred. Commit if there was no panic, rollback if there was a 7 panic. Usage: 8 9 defer DbTxDone(conn) 10 */ 11 func DbTxDone[A DbTx](val A) { 12 DbTxDoneWith(val, gg.AnyErrTracedAt(recover(), 1)) 13 } 14 15 /* 16 Commit if there was no error, rollback if there was an error. 17 Used internally by `DbTxDone`. 18 */ 19 func DbTxDoneWith[A DbTx](val A, err error) { 20 if err != nil { 21 _ = val.Rollback() 22 panic(err) 23 } 24 25 defer gg.Detail(`failed to commit DB transaction`) 26 gg.Try(val.Commit()) 27 }