Documentation
¶
Index ¶
- Variables
- func NewCurrentUow(ctx context.Context, u *UnitOfWork) context.Context
- func WithCurrentUnitOfWork(ctx context.Context, fn func(ctx context.Context) error) (err error)
- func WithUnitOfWork(ctx context.Context, u *UnitOfWork, fn func(ctx context.Context) error) (err error)
- type Config
- type DbFactory
- type IdGenerator
- type KeyFormatter
- type Manager
- type Option
- type TransactionalDb
- type Txn
- type UnitOfWork
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrUnitOfWorkNotFound = errors.New("unit of work not found, please wrap with manager.WithNew")
)
Functions ¶
func NewCurrentUow ¶
func NewCurrentUow(ctx context.Context, u *UnitOfWork) context.Context
func WithCurrentUnitOfWork ¶
WithCurrentUnitOfWork wrap a function into current unit of work. Automatically Rollback if function returns error
func WithUnitOfWork ¶
Types ¶
type Config ¶
type Config struct { DisableNestedTransaction bool // contains filtered or unexported fields }
type DbFactory ¶
type DbFactory func(ctx context.Context, keys ...string) (TransactionalDb, error)
DbFactory resolve transactional db by database keys
type IdGenerator ¶
type KeyFormatter ¶
var ( DefaultKeyFormatter KeyFormatter = func(keys ...string) string { return strings.Join(keys, "/") } )
type Manager ¶
type Manager interface { CreateNew(ctx context.Context, opt ...*sql.TxOptions) (*UnitOfWork, error) // WithNew create a new unit of work and execute [fn] with this unit of work WithNew(ctx context.Context, fn func(ctx context.Context) error, opt ...*sql.TxOptions) error }
func NewManager ¶
type Option ¶
type Option func(*Config)
func WithDisableNestedNestedTransaction ¶
func WithDisableNestedNestedTransaction() Option
func WithIdGenerator ¶
func WithIdGenerator(idGen IdGenerator) Option
func WithKeyFormatter ¶
func WithKeyFormatter(f KeyFormatter) Option
type TransactionalDb ¶
type UnitOfWork ¶
type UnitOfWork struct {
// contains filtered or unexported fields
}
func FromCurrentUow ¶
func FromCurrentUow(ctx context.Context) (u *UnitOfWork, ok bool)
func (*UnitOfWork) Commit ¶
func (u *UnitOfWork) Commit() error
func (*UnitOfWork) GetId ¶
func (u *UnitOfWork) GetId() string
func (*UnitOfWork) Rollback ¶
func (u *UnitOfWork) Rollback() error
Click to show internal directories.
Click to hide internal directories.