15adaebfcd
DRAFT PR : WIP working through ideas for integration * movearound * attempttwo * openapi * further sanding * fix * start on tests * runthroughsingleconfig * somechanges * reflectissue * removeerrs * mostlyremovepanic * removeenv * noncfgtests * go * repo * fix service config test * add PWD to all * test fix * fix lint * todo for later * passingunittests * alltests * testlogger * testloggername * clean
31 lines
506 B
Go
31 lines
506 B
Go
package database
|
|
|
|
import (
|
|
"context"
|
|
"queryorchestration/internal/database/repository"
|
|
)
|
|
|
|
func (b *BaseConfig) 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
|
|
}
|