Documentation
¶
Overview ¶
Package txctx is a Fiber v2 + GORM middleware that manages a request-scoped database transaction. See txctxv3 for the Fiber v3 variant.
Index ¶
- func BoolPtr(v bool) *bool
- func DB(c *fiber.Ctx) *gorm.DB
- func DBFromCtx(ctx context.Context) *gorm.DB
- func Middleware(db *gorm.DB, cfg Config) fiber.Handler
- func OnCommit(c *fiber.Ctx, fn func(*gorm.DB) error)
- func OnCommitCtx(ctx context.Context, fn func(*gorm.DB) error)
- func OnRollback(c *fiber.Ctx, fn func(*gorm.DB) error)
- func OnRollbackCtx(ctx context.Context, fn func(*gorm.DB) error)
- func Outside(c *fiber.Ctx) *gorm.DB
- func OutsideCtx(ctx context.Context) *gorm.DB
- type Config
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DB ¶
DB returns the request-scoped *gorm.DB. With LazyTx the first write call transparently opens BEGIN; reads stay outside any transaction.
func Middleware ¶
Middleware returns a Fiber v2 middleware that manages a request-scoped GORM transaction with timeout-triggered rollback and commit/rollback callbacks.
func OnCommit ¶
OnCommit registers fn to run only if the transaction commits successfully. Callbacks run in registration order; the first error stops the chain and is reported via Config.OnCallbackError (the commit itself is not undone).
func OnCommitCtx ¶
OnCommitCtx is the context.Context variant of OnCommit.
func OnRollback ¶
OnRollback registers fn to run if the transaction rolls back.
func OnRollbackCtx ¶
OnRollbackCtx is the context.Context variant of OnRollback.