txctx

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: MIT Imports: 4 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolPtr

func BoolPtr(v bool) *bool

BoolPtr is a helper for setting Config.LazyTx inline.

func DB

func DB(c *fiber.Ctx) *gorm.DB

DB returns the request-scoped *gorm.DB. With LazyTx the first write call transparently opens BEGIN; reads stay outside any transaction.

func DBFromCtx

func DBFromCtx(ctx context.Context) *gorm.DB

DBFromCtx is the context.Context variant of DB.

func Middleware

func Middleware(db *gorm.DB, cfg Config) fiber.Handler

Middleware returns a Fiber v2 middleware that manages a request-scoped GORM transaction with timeout-triggered rollback and commit/rollback callbacks.

func OnCommit

func OnCommit(c *fiber.Ctx, fn func(*gorm.DB) error)

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

func OnCommitCtx(ctx context.Context, fn func(*gorm.DB) error)

OnCommitCtx is the context.Context variant of OnCommit.

func OnRollback

func OnRollback(c *fiber.Ctx, fn func(*gorm.DB) error)

OnRollback registers fn to run if the transaction rolls back.

func OnRollbackCtx

func OnRollbackCtx(ctx context.Context, fn func(*gorm.DB) error)

OnRollbackCtx is the context.Context variant of OnRollback.

func Outside

func Outside(c *fiber.Ctx) *gorm.DB

Outside returns a *gorm.DB whose context is decoupled from the request cancellation (so it survives request timeout) but preserves request values for tracing/logging propagation.

func OutsideCtx

func OutsideCtx(ctx context.Context) *gorm.DB

OutsideCtx is the context.Context variant of Outside.

Types

type Config

type Config = txcore.Config

Config re-exports the shared core configuration.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL