gotransaction

package
v1.2.91 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

事务性操作 主要在go-zero 框架下执行

初始化 : TransactionModel: transactionex.NewModel(conn, cacheConf),

userInserter := func(session sqlx.Session) error {
    return l.svcCtx.UserModel.InsertWithTx(l.ctx, session, newUserInfo)
}
deviceInserter := func(session sqlx.Session) error {
    return l.svcCtx.DeviceModel.InsertWithTx(l.ctx, session, deviceInfo)
}
inserters := []transactionex.TableTransactionFunc{
    userInserter,
    deviceInserter,
}
err := l.svcCtx.TransactionModel.Transactions(inserters)
if err != nil {
    return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "Register InsertWithTx error:%v in:%+v", err, in)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterTransactionHandler

func RegisterTransactionHandler(key string, handleFunc TransactionHandler)

Types

type Model

type Model struct {
	sqlc.CachedConn
}

func NewModel

func NewModel(conn sqlx.SqlConn, c cache.CacheConf) *Model

func (*Model) Transactions

func (m *Model) Transactions(inserters []TableTransactionFunc) error

Transaction 事务方式插入多个表的数据

type TableTransactionFunc

type TableTransactionFunc func(session sqlx.Session) error

type TransactionHandler

type TransactionHandler interface {
	InsertTransactions(ctx context.Context, session sqlx.Session, info string) error
	DeleteTransactions(ctx context.Context, session sqlx.Session, info string) error
}

func GetTransactionHandler

func GetTransactionHandler(key string) TransactionHandler

type TransactionManager

type TransactionManager struct {
	TransactionHandlers map[string]TransactionHandler
}

Jump to

Keyboard shortcuts

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