ouw

package module
v0.0.0-...-6cea03b Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2021 License: MIT Imports: 6 Imported by: 0

README

ouw

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicateKey  = errors.New("duplicate dbKey")
	ErrDbKeyNotFound = errors.New("dbKey not found")
)
View Source
var (
	ErrUnitOfWorkNotFound = errors.New("unit of work not found, please wrap with manager.WithNew")
)

Functions

This section is empty.

Types

type DbFactory

type DbFactory func(ctx context.Context, key string) TransactionalDb

type Manager

type Manager interface {
	Register(key string, f DbFactory) (err error)
	RegisterIfNot(key string, f DbFactory)
	Resolve(ctx context.Context, key string) (db TransactionalDb, ok bool)
	// 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

func NewManager() Manager

type TransactionalDb

type TransactionalDb interface {
	// Begin a transaction
	Begin(ctx context.Context, opt ...*sql.TxOptions) (db interface{}, err error)
}

type UnitOfWork

type UnitOfWork interface {
	Commit() error
	Rollback() error
	GetTxDb(ctx context.Context, key string) (tx interface{}, err error)
}

func FromCurrentUow

func FromCurrentUow(ctx context.Context) (u UnitOfWork, ok bool)

func NewUnitOfWork

func NewUnitOfWork(m Manager, opt ...*sql.TxOptions) UnitOfWork

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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