Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNoTranInContext = errors.New("no transaction in context")
Functions ¶
func Transaction ¶
func Transaction(ctx context.Context, db *sqlx.DB, ct CtxTransaction, f func(ctx context.Context) error) error
Transaction calls func in transaction. Rollbacks if function return error.
Example:
err := Transaction(ctx, ct, func(ctx context.Context) error { m, err := ... if err != nil { return err } // other db operation return ... })
Special method for generated repositories.
Types ¶
type CtxTransaction ¶
type CtxTransaction interface { TxFromContext(ctx context.Context) (*sqlx.Tx, error) NewContextWithTx(ctx context.Context, tx *sqlx.Tx) (context.Context, error) }
CtxTransaction defines ctx transaction interface which allow transfer *sqlx.Tx via context.Context.
type Option ¶
type Option func(ds *goqu.SelectDataset)
func WithFilter ¶ added in v0.10.1
func WithFilter(exp ...exp.Expression) Option
WithFilter option used to filter select.
func WithLockForUpdate ¶
func WithLockForUpdate() Option
WithLockForUpdate option must be used for read methods to lock for update.
func WithOrder ¶ added in v0.10.1
func WithOrder(order ...exp.OrderedExpression) Option
WithOrder option used to order select.
type RepositoryOpt ¶
type RepositoryOpt struct {
CtxTran CtxTransaction
}
type RepositoryOption ¶
type RepositoryOption func(o *RepositoryOpt)
func WithCtxTran ¶
func WithCtxTran(ct CtxTransaction) RepositoryOption
WithCtxTran option used to set custom transaction getter from context.
type StdCtxTran ¶
StdCtxTran implements CtxTransaction via sqlx.DB. Used as default for generated repository.
func (*StdCtxTran) NewContextWithTx ¶
func (*StdCtxTran) TxFromContext ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package examples contains examples.
|
Package examples contains examples. |
Click to show internal directories.
Click to hide internal directories.