Documentation ¶
Index ¶
- Variables
- type LogLevel
- type LoggerConfig
- type Options
- type PropagationType
- type Transaction
- func (t *Transaction) Commit() error
- func (t *Transaction) Delete(query string, arg interface{}) (int64, error)
- func (t *Transaction) GetOne(dest interface{}, query string, args ...interface{}) error
- func (t *Transaction) Insert(query string, arg interface{}) (int64, error)
- func (t *Transaction) NamedExec(query string, arg interface{}) (int64, error)
- func (t *Transaction) NamedQuery(dest interface{}, query string, arg interface{}) error
- func (t *Transaction) Rollback() error
- func (t *Transaction) Select(dest interface{}, query string, args ...interface{}) error
- func (t *Transaction) String() string
- func (t *Transaction) Update(query string, arg interface{}) (int64, error)
- type TxManager
- type ZapLogger
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidTxState is returned when transaction is not initialized ErrInvalidTxState = errors.New("gotx: tx is already committed or rolled back") )
Functions ¶
This section is empty.
Types ¶
type LoggerConfig ¶ added in v0.2.0
type LoggerConfig struct { Level LogLevel `json:"level" yaml:"level"` Format string `json:"format" yaml:"format"` }
LoggerConfig for zap
type Options ¶
type Options struct { // PropagationType specifies how the tx manager manages transaction propagation Propagation PropagationType IsolationLevel sql.IsolationLevel }
Options declares some configurable options when starts a transaction
type PropagationType ¶
type PropagationType uint8
PropagationType is an alias of uint8
const ( // Required specifies the txFunc will be run in an existing db tx. If there's no existing tx, // tx manager will create a new one for it. PropagationRequired PropagationType = iota // New specifies the txFunc will be run in a separated new db tx. PropagationNew )
constants that defines transaction propagation patterns
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction is a logical transaction which wraps a underlying db transaction (physical transaction)
func NewTx ¶
func NewTx(t *rawTx, txID string, requiredNew bool) *Transaction
func (*Transaction) Commit ¶
func (t *Transaction) Commit() error
func (*Transaction) Delete ¶
func (t *Transaction) Delete(query string, arg interface{}) (int64, error)
func (*Transaction) GetOne ¶
func (t *Transaction) GetOne(dest interface{}, query string, args ...interface{}) error
GetOne is the sqlx.Get wrapper
func (*Transaction) Insert ¶
func (t *Transaction) Insert(query string, arg interface{}) (int64, error)
Insert implements sql insert logic and returns generated ID
func (*Transaction) NamedExec ¶ added in v0.2.0
func (t *Transaction) NamedExec(query string, arg interface{}) (int64, error)
NamedExec is a generic executor that does not return rows. It inspect the query to check if it has IN clause and process it with sqlx.In. Docs from sqlx doc:
Named queries are common to many other database packages. They allow you to use a bindvar syntax which refers to the names of struct fields or map keys to bind variables a query, rather than having to refer to everything positionally. The struct field naming conventions follow that of StructScan, using the NameMapper and the db struct tag.
func (*Transaction) NamedQuery ¶ added in v0.2.0
func (t *Transaction) NamedQuery(dest interface{}, query string, arg interface{}) error
func (*Transaction) Rollback ¶
func (t *Transaction) Rollback() error
rollback reset the refCount and do the real rollback.
func (*Transaction) Select ¶
func (t *Transaction) Select(dest interface{}, query string, args ...interface{}) error
func (*Transaction) String ¶
func (t *Transaction) String() string
type TxManager ¶
type TxManager struct {
// contains filtered or unexported fields
}
TxManager implements a basic transaction manager
func NewTxManager ¶
type ZapLogger ¶ added in v0.2.0
type ZapLogger struct {
*zap.SugaredLogger
}
var ( // A package wide logger instance Logger *ZapLogger )
func NewLogger ¶ added in v0.2.0
func NewLogger(cfg *LoggerConfig) *ZapLogger