Documentation
¶
Index ¶
- Constants
- Variables
- func Extract[T any](ctx context.Context, key CtxKey) (T, error)
- func NewPGContext(ctx context.Context, migrations *embed.FS) (context.Context, error)
- func NewPGContextTX(ctx context.Context, opts *sql.TxOptions) (context.Context, func(commit bool) error, error)
- func PGContext(ctx context.Context) (bun.IDB, error)
- type CtxKey
Constants ¶
View Source
const ( // PostgresDNSEnv is the env variable that should contain the Postgres connection string (Data Source Name or DSN). // // The DSN string should be in the format: // // postgres://[user]:[password]@[host]:[port]/[database]?[...pgoptions] PostgresDNSEnv = "DSN" )
Variables ¶
View Source
var ErrNoDNS = errors.New("missing DSN environment variable")
View Source
var ErrUnsupportedContext = errors.New("unsupported context")
Functions ¶
func Extract ¶
Extract a value from a context with the correct typing, It fails if the value is missing or has the wrong type.
func NewPGContext ¶
NewPGContext returns a new context with a shared PG connection.
func NewPGContextTX ¶
func NewPGContextTX(ctx context.Context, opts *sql.TxOptions) (context.Context, func(commit bool) error, error)
NewPGContextTX creates a new Postgres context where the virtual database is replaced by a transaction.
The parent context MUST contain a virtual Postgres instance, either created with NewPGContext or NewPGContextTX.
The returned cancel function MUST be called with the argument set to true for the transaction to be committed. Omitting this call will automatically roll back the whole transaction.
Types ¶
Click to show internal directories.
Click to hide internal directories.