Documentation ¶
Index ¶
- Variables
- func Exec(ctx context.Context, query string, params ...interface{}) (sql.Result, error)
- func Get(ctx context.Context, dest interface{}, query string, params ...interface{}) error
- func Select(ctx context.Context, dest interface{}, query string, params ...interface{}) error
- func WithQuerier(ctx context.Context, q Querier) context.Context
- type Conn
- type Querier
- type Rows
- type Tx
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNoQuerrier = errors.New("Querrier missing from context")
Functions ¶
Types ¶
type Conn ¶
type Conn interface { Querier // Begin is an alternative way of starting a transaction if you need more // control over it. It is strongly recommended that you use `defer // tx.Rollback()` directly after acquiring the transaction to ensure it is // closed even in the case of a panic. Begin(context.Context) (Tx, error) // Tx is wraps a transaction. If no error is returned from the callback, the // transaction will be committed, otherwise it will be aborted. Tx(context.Context, func(context.Context, Querier) error) error }
Conn is a stripped down convenience wrapper around sqlx (which is, in-turn, a wrapper around database/sql) meant to make DB access more convenient and easier to fall into the pit of success.
type Querier ¶
type Querier interface { // Exec is meant for running queries which don't read data, such as INSERTs // or UPDATES. Exec(ctx context.Context, query string, params ...interface{}) (sql.Result, error) // Get is meant for SELECT queries returning a single row. It will return an // error if no rows are returned. Get(ctx context.Context, dest interface{}, query string, params ...interface{}) error // Select is meant for SELECT queries returning an unknown number of rows // but which should easily fit into memory. Select(ctx context.Context, dest interface{}, query string, params ...interface{}) error // Query is meant for SELECT queries which return an unknown number of rows // and may not all fit into memory. The Rows object can be used to scan the // results one row at a time. Query(ctx context.Context, query string, params ...interface{}) (*Rows, error) }
Querier is the common interface between a DB and a Tx.
type Tx ¶
type Tx interface { Querier // Rollback will roll back the transaction. Rollback() error // Commit will commit the transaction. Commit() error }
Tx is a Querier representing a transaction rather than a connection. The first call to either Rollback or Commit will end the transaction any calls afterwords will be dropped and an error returned.
Click to show internal directories.
Click to hide internal directories.