Add WithContext on DatabaseMap
diff --git a/db/interfaces.go b/db/interfaces.go index 731bc7b..01d62c1 100644 --- a/db/interfaces.go +++ b/db/interfaces.go
@@ -50,6 +50,7 @@ Inserter SelectExecer Begin() (Transaction, error) + WithContext(ctx context.Context) gorp.SqlExecutor } // Executor offers the full combination of OneSelector, Inserter, SelectExecer
diff --git a/db/transaction.go b/db/transaction.go index ec1e23a..8a5b250 100644 --- a/db/transaction.go +++ b/db/transaction.go
@@ -1,6 +1,10 @@ package db -import "context" +import ( + "context" + + "github.com/go-gorp/gorp/v3" +) // txFunc represents a function that does work in the context of a transaction. type txFunc func(txWithCtx Executor) (interface{}, error) @@ -12,7 +16,9 @@ func WithTransaction(ctx context.Context, dbMap DatabaseMap, f txFunc) (interface{}, error) { ctx, cancel := context.WithCancel(ctx) defer cancel() - tx, err := dbMap.Begin() + + se := dbMap.WithContext(ctx).(WrappedExecutor).SqlExecutor.(*gorp.DbMap) + tx, err := se.Begin() if err != nil { return nil, err }