Files

23 lines
416 B
Go

package projectinstance
import (
"context"
"github.com/jackc/pgx/v5"
)
type txKey struct{}
// WithTx binds a fenced worker transaction so bookkeeping writes join the same UoW.
func WithTx(ctx context.Context, tx pgx.Tx) context.Context {
if tx == nil {
return ctx
}
return context.WithValue(ctx, txKey{}, tx)
}
func txFrom(ctx context.Context) pgx.Tx {
tx, _ := ctx.Value(txKey{}).(pgx.Tx)
return tx
}