fixed: error handling in commit;
refactor: exposed untransactional queries for transactional db helper again but with a clearer name this time since it still may be useful
This commit is contained in:
@@ -18,7 +18,7 @@ type DbHelper struct {
|
|||||||
|
|
||||||
type dbHelperTransactionImpl struct {
|
type dbHelperTransactionImpl struct {
|
||||||
CTX context.Context
|
CTX context.Context
|
||||||
queries Queries
|
TXlessQueries Queries
|
||||||
TX pgx.Tx
|
TX pgx.Tx
|
||||||
TXQueries Queries
|
TXQueries Queries
|
||||||
}
|
}
|
||||||
@@ -48,7 +48,7 @@ func NewDbHelperTransaction(dbContext DbContext) (DbHelperTransaction, *dbHelper
|
|||||||
|
|
||||||
obj := &dbHelperTransactionImpl{
|
obj := &dbHelperTransactionImpl{
|
||||||
CTX: ctx,
|
CTX: ctx,
|
||||||
queries: *queries,
|
TXlessQueries: *queries,
|
||||||
TX: tx,
|
TX: tx,
|
||||||
TXQueries: *txQueries,
|
TXQueries: *txQueries,
|
||||||
}
|
}
|
||||||
@@ -58,10 +58,16 @@ func NewDbHelperTransaction(dbContext DbContext) (DbHelperTransaction, *dbHelper
|
|||||||
|
|
||||||
// Commit implements DbHelperTransaction.
|
// Commit implements DbHelperTransaction.
|
||||||
func (d *dbHelperTransactionImpl) Commit() error {
|
func (d *dbHelperTransactionImpl) Commit() error {
|
||||||
err := d.TX.Commit(d.CTX)
|
errCommit := d.TX.Commit(d.CTX)
|
||||||
|
|
||||||
if err != nil {
|
if errCommit != nil {
|
||||||
return err
|
errRollback := d.TX.Rollback(d.CTX)
|
||||||
|
|
||||||
|
if errRollback != nil {
|
||||||
|
return errRollback
|
||||||
|
}
|
||||||
|
|
||||||
|
return errCommit
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user