trans

package
v0.0.0-...-fb2f31d Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Commit

func Commit(ctx context.Context) error

Commit 提交事务

func GORMTx

func GORMTx(ctx context.Context, db *gorm.DB) *gorm.DB

func Middleware

func Middleware(opts ...ManagerOption) middleware.Middleware

Middleware 用于处理事务提交和回滚的中间件。 opts: ManagerOption 采用先进先出的形式

func Rollback

func Rollback(ctx context.Context) error

Rollback 回滚事务

func SqlxTx

func SqlxTx(ctx context.Context, db *sqlx.DB) (*sqlx.Tx, error)

Types

type GORMTransaction

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

func (*GORMTransaction) Commit

func (tx *GORMTransaction) Commit(ctx context.Context) error

Commit Gorm事务提交处理函数

func (*GORMTransaction) Rollback

func (tx *GORMTransaction) Rollback(ctx context.Context) error

Rollback GORM事务回滚处理函数

type GORMTransactionKey

type GORMTransactionKey struct{}

GORMTransactionKey 事务协调器中GORM事务唯一键

type InitHandler

type InitHandler func(*Orchestrator)

初始化事务处理器函数

type ManagerOption

type ManagerOption func(*manager)

ManagerOption 事务管理器选项设置

func AddInitHandler

func AddInitHandler(f InitHandler) ManagerOption

AddInitHandler 初始化时立刻添加事务

func GORM

func GORM(db *gorm.DB) ManagerOption

func Logger

func Logger(logger log.Logger) ManagerOption

Logger 设置事务协调器日志

func Sqlx

func Sqlx(db *sqlx.DB) ManagerOption

type Orchestrator

type Orchestrator struct {
	// Tx 有序的 map[struct{}]Transaction
	Tx *orderedmap.OrderedMap[struct{}, Transaction]
}

Orchestrator 协调器

func GetOrchestratorFromContext

func GetOrchestratorFromContext(ctx context.Context) *Orchestrator

GetOrchestratorFromContext 从上下文中获取事务协调器

type OrchestratorContextKey

type OrchestratorContextKey struct{}

OrchestratorContextKey 上下文的事务协调器唯一键

type SqlxTransaction

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

func (*SqlxTransaction) Commit

func (tx *SqlxTransaction) Commit(ctx context.Context) error

Commit Sqlx事务提交处理函数

func (*SqlxTransaction) Rollback

func (tx *SqlxTransaction) Rollback(ctx context.Context) error

Rollback Sqlx事务回滚处理函数

type SqlxTransactionKey

type SqlxTransactionKey struct{}

SqlxTransactionKey 事务协调器中Sqlx事务唯一键

type Transaction

type Transaction interface {
	Commit(context.Context) error
	Rollback(context.Context) error
}

Transaction 事务

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳