Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
Get returns the database pointer embedded in the current context. The database pointer can be embedded in the current context using With.
Types ¶
type ExecerContext ¶
type ExecerContext interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}
ExecerContext defines an interface which supports ExecContext calls. Implemented by sql.Conn, sql.DB, sql.Stmt, sql.Tx.
type QueryerContext ¶
type QueryerContext interface {
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
}
QueryerContext defines an interface which supports QueryContext calls. Implemented by sql.Conn, sql.DB, sql.Stmt, sql.Tx.
type RollbackTx ¶
RollbackTx is a sql.Tx which supports automatic rollback. defer a call to MaybeRollback(), then call (*RollbackTx).Commit() instead of (*sql.Tx).Commit() to avoid having the transaction rolled back by the defer.
func Begin ¶
func Begin(c context.Context) (*RollbackTx, error)
Begin begins a transaction using the database pointer embedded in the current context.
func (*RollbackTx) MaybeRollback ¶
func (r *RollbackTx) MaybeRollback(c context.Context) error
MaybeRollback rolls back the transaction if (*RollbackTx).Commit() hasn't been called. Logs the error if the rollback itself fails.