tx

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package tx 提供事务管理,支持 ctx 注入事务 DB

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context, defaultDB *gorm.DB) *gorm.DB

FromContext 从 ctx 获取 DB(优先返回事务 DB)

func GetDB

func GetDB(ctx context.Context, defaultDB *gorm.DB) *gorm.DB

GetDB 获取 DB(用于 dao 层)

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager 事务管理器

func NewManager

func NewManager(db *gorm.DB) *Manager

NewManager 创建事务管理器

func (*Manager) Do

func (m *Manager) Do(ctx context.Context, fn func(ctx context.Context) error) error

Do 在事务中执行函数

Jump to

Keyboard shortcuts

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