Documentation ¶
Overview ¶
Package transaction provides a client for a live transaction, and interfaces for some relevant sql types. The transaction client automatically performs rollbacks on failures. The use of this package simplifies testing for callers by making the underlying transaction mock-able.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client provides a way to interact with the underlying sql transaction.
func (*Client) Cancel ¶
Cancel rollbacks the transaction without wrapping an error. This only needs to be called if Client has not returned an error yet or has not committed. Otherwise, transaction has already rolled back, or in the case of Commit() it is too late.
func (*Client) Exec ¶
Exec uses the sqlTX Exec() with the given stmt and args. The transaction will be automatically rolled back if Exec() returns an error.
type SQLTx ¶
type SQLTx interface { Exec(query string, args ...any) (sql.Result, error) Stmt(stmt *sql.Stmt) *sql.Stmt Commit() error Rollback() error }
SQLTx represents a sql transaction
type Stmt ¶
type Stmt interface { Exec(args ...any) (sql.Result, error) Query(args ...any) (*sql.Rows, error) QueryContext(ctx context.Context, args ...any) (*sql.Rows, error) }
Stmt represents a sql stmt. It is used as a return type to offer some testability over returning sql's Stmt type because we are able to mock its outputs and do not need an actual connection.