7001ca854c
Queuing Changes and Cfg Testing * staarting * staarting * startedpush * note * save * mocking * removederrs * fixtests * cleanuperrs * newenvsetup * preppingtests * queue * mmovetocfgpassunittests * sortoutconfig * passinginteg * deps * fixtests
31 lines
504 B
Go
31 lines
504 B
Go
package database
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database/repository"
|
|
)
|
|
|
|
func (b *DBConfig) ExecuteDBTransaction(ctx context.Context, executeQueries func(context.Context, *repository.Queries) error) error {
|
|
tx, err := b.DBPool.Begin(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer func() {
|
|
_ = tx.Rollback(ctx)
|
|
}()
|
|
|
|
qtx := b.DBQueries.WithTx(tx)
|
|
|
|
err = executeQueries(ctx, qtx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = tx.Commit(ctx)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return nil
|
|
}
|