diff --git a/go.mod b/go.mod index 2e1c128..a234bb8 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ toolchain go1.26.5 require ( github.com/jackc/pgx/v5 v5.10.0 - github.com/spice-framework/spice v0.0.0-20260805222830-a2ecd56df246 + github.com/spice-framework/spice v0.1.0-preview.4 ) require ( diff --git a/go.sum b/go.sum index 3beb183..0ee83ce 100644 --- a/go.sum +++ b/go.sum @@ -13,8 +13,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/spice-framework/development v0.0.0-20260806132124-4c308d1b9fda h1:2NwMsYJ6BqeA5johEh5gXxqEyf5RoVsKZyNH4AMR4Yo= github.com/spice-framework/development v0.0.0-20260806132124-4c308d1b9fda/go.mod h1:0lIxjVtv+p4iTrvLJm05OjimS2MSrIqM1xPR7Q0GHEg= -github.com/spice-framework/spice v0.0.0-20260805222830-a2ecd56df246 h1:IAPcr8bmwyeNQWME5bUWg/NvDVGoBJY+TRumFXMPXR8= -github.com/spice-framework/spice v0.0.0-20260805222830-a2ecd56df246/go.mod h1:dBZV5UZcbY6pzhfGNtvAwQIJ8YsFna+jf1SAlmukJfk= +github.com/spice-framework/spice v0.1.0-preview.4 h1:jfUSUquq9rQN/FMI6zvBEJZYX12ZVeJAQmusvjy/3T8= +github.com/spice-framework/spice v0.1.0-preview.4/go.mod h1:dBZV5UZcbY6pzhfGNtvAwQIJ8YsFna+jf1SAlmukJfk= github.com/spice-framework/toolchain v0.0.0-20260806133530-71211498297c h1:US3ChgXYhIXFZ5VNYQ2BjuiTbStVNEyC1cBjxN3SCXM= github.com/spice-framework/toolchain v0.0.0-20260806133530-71211498297c/go.mod h1:/U0xhEiz4xGpiCCS560gjgDiixDh5lR4NXVbVPmrmh8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= diff --git a/vendor/github.com/spice-framework/spice/data/transaction.go b/vendor/github.com/spice-framework/spice/data/transaction.go index e29b5f4..65f4834 100644 --- a/vendor/github.com/spice-framework/spice/data/transaction.go +++ b/vendor/github.com/spice-framework/spice/data/transaction.go @@ -27,6 +27,21 @@ type Executor interface { QueryRowContext(context.Context, string, ...any) *sql.Row } +type executorContextKey struct{} + +// ExecutorFromContext returns the transaction-owned executor installed by +// Manager.Within. Generated service decorators use this explicit accessor so +// repository implementations can participate without receiving a transaction +// parameter through every service method. It returns false outside a managed +// transaction. +func ExecutorFromContext(ctx context.Context) (Executor, bool) { + if ctx == nil { + return nil, false + } + executor, ok := ctx.Value(executorContextKey{}).(Executor) + return executor, ok && executor != nil +} + // Definition is compiler-owned metadata for one transaction boundary. type Definition struct { ID string @@ -128,7 +143,12 @@ func (manager *Manager) Within( panic(recovered) }() - if err := work(observedContext, tx); err != nil { + transactionContext := context.WithValue( + observedContext, + executorContextKey{}, + Executor(tx), + ) + if err := work(transactionContext, tx); err != nil { workErr := fmt.Errorf("execute transaction %q: %w", definition.ID, err) resultErr = errors.Join(workErr, rollback(tx, definition.ID)) finish(Result{Definition: definition, Duration: time.Since(started), Err: resultErr}) diff --git a/vendor/modules.txt b/vendor/modules.txt index 0175a15..2d7fc8c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -33,7 +33,7 @@ github.com/spice-framework/development/internal/libraryrelease github.com/spice-framework/development/internal/process github.com/spice-framework/development/internal/verify github.com/spice-framework/development/internal/workspace -# github.com/spice-framework/spice v0.0.0-20260805222830-a2ecd56df246 +# github.com/spice-framework/spice v0.1.0-preview.4 ## explicit; go 1.26.0 github.com/spice-framework/spice/annotation github.com/spice-framework/spice/annotation/sdk/starter