Documentation ¶
Index ¶
- type DBTxManager
- type DBTxOpt
- type GormTxManager
- func (s *GormTxManager) AutoDB(ctx context.Context) *gorm.DB
- func (s *GormTxManager) BackupDB() *gorm.DB
- func (s *GormTxManager) CloseMainTx(ctx context.Context, txid uint64, err *error)
- func (s *GormTxManager) MainDB(ctx context.Context) *gorm.DB
- func (s *GormTxManager) MustMainTx(ctx context.Context) *gorm.DB
- func (s *GormTxManager) OpenMainTx(ctx context.Context, opts ...DBTxOpt) (context.Context, uint64)
- type NameDB
- type Option
- type Persistencer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DBTxManager ¶ added in v1.0.3
type DBTxManager interface { // OpenMainTx 开启 main库 事物 OpenMainTx(ctx context.Context, opts ...DBTxOpt) (context.Context, uint64) // CloseMainTx 关闭 main库 事务 CloseMainTx(ctx context.Context, txid uint64, err *error) // MainDB 获取 main db,如果已经开启 main db tx,则返回 main db tx MainDB(ctx context.Context) *gorm.DB // BackupDB 获取 Backup db BackupDB() *gorm.DB // AutoDB 获取 db,如果已经开启 main db tx,则返回 db tx,否则 返回 backup db AutoDB(ctx context.Context) *gorm.DB // MustMainTx 获取 main db tx,如果已经开启 main db tx,则返回 main db tx,否则 panic MustMainTx(ctx context.Context) *gorm.DB }
type GormTxManager ¶
type GormTxManager struct {
// contains filtered or unexported fields
}
GormTxManager db 事务管理器 mainDB, backupDB *gorm.DB // 默认主从库实例 tid2Tx sync.Map // tid(事务ID) 对应的 事务
func NewGormTxManager ¶
func NewGormTxManager(mainDB, backupDB *gorm.DB) *GormTxManager
func NewGormTxManagerWithClauses ¶ added in v1.0.1
func NewGormTxManagerWithClauses(db *gorm.DB) *GormTxManager
NewGormTxManagerWithClauses 使用 DBResolver 读写分离
func (*GormTxManager) AutoDB ¶
func (s *GormTxManager) AutoDB(ctx context.Context) *gorm.DB
AutoDB 获取 db,如果已经开启 main db tx,则返回 db tx,否则 返回 backup db
func (*GormTxManager) CloseMainTx ¶
func (s *GormTxManager) CloseMainTx(ctx context.Context, txid uint64, err *error)
CloseMainTx 关闭 main库 事务 参数: ctx: 开启 main库 事务返回的新的context txid: 开启 main库 事务返回的事务ID err: 判断是提交事务还是回滚事务
func (*GormTxManager) MainDB ¶
func (s *GormTxManager) MainDB(ctx context.Context) *gorm.DB
MainDB 获取 main db,如果已经开启 main db tx,则返回 main db tx
func (*GormTxManager) MustMainTx ¶
func (s *GormTxManager) MustMainTx(ctx context.Context) *gorm.DB
MustMainTx 获取 main db tx,如果已经开启 main db tx,则返回 main db tx,否则 panic
func (*GormTxManager) OpenMainTx ¶
OpenMainTx 开启 main库 事务 return 新的context 与 事务ID
type Persistencer ¶ added in v1.0.3
type Persistencer interface {
DBTxManager() DBTxManager
}
Click to show internal directories.
Click to hide internal directories.