Documentation
¶
Overview ¶
Package sqlx contains utilities for working with SQL databases.
Index ¶
- func Begin(ctx context.Context, db *sql.DB) *sql.Tx
- func Commit(tx *sql.Tx)
- func Conn(ctx context.Context, db *sql.DB) *sql.Conn
- func Exec(ctx context.Context, db DB, query string, args ...interface{}) sql.Result
- func ExecRow(ctx context.Context, db DB, query string, args ...interface{})
- func Insert(ctx context.Context, db DB, query string, args ...interface{}) int64
- func Must(err error)
- func Prepare(ctx context.Context, db DB, query string) *sql.Stmt
- func QueryBool(ctx context.Context, db DB, query string, args ...interface{}) (v bool)
- func QueryInt64(ctx context.Context, db DB, query string, args ...interface{}) (v int64)
- func QueryInto(ctx context.Context, db DB, value interface{}, query string, ...)
- func Recover(err *error)
- func Scan(rows Scanner, targets ...interface{})
- func ScanInt64(rows Scanner) int64
- func TryExecRow(ctx context.Context, db DB, query string, args ...interface{}) bool
- func TryInsert(ctx context.Context, db DB, query string, args ...interface{}) (int64, bool)
- type DB
- type PanicSentinel
- type Scanner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExecRow ¶
ExecRow executes a statement on the given DB.
It panics if the statement does not affect exactly one row.
Note that for MySQL an column value must actually change to consider the row updated. Further, it returns a value of 2 for an INSERT .. ON DUPLICATE KEY UPDATE that results in a change to an existing row.
func QueryBool ¶
QueryBool executes a single-column, single-row query on the given DB and returns a single bool result.
func QueryInt64 ¶
QueryInt64 executes a single-column, single-row query on the given DB and returns a single uint64 result.
func QueryInto ¶
QueryInto executes single-column, single-row query on the given DB and scans the result into a value.
func Recover ¶
func Recover(err *error)
Recover recovers from a panic caused by one of the MustXXX() functions.
It is intended to be used in a defer statement. The error that caused the panic is assigned to *err.
func Scan ¶
func Scan(rows Scanner, targets ...interface{})
Scan scans values from a row or row-set.
func TryExecRow ¶
TryExecRow executes a statement on the given DB.
It returns false if the update does not affect exactly one row.
Note that for MySQL an column value must actually change to consider the row updated. Further, it returns a value of 2 for an INSERT .. ON DUPLICATE KEY UPDATE that results in a change to an existing row.
Types ¶
type DB ¶
type DB interface { QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error) }
DB is an interface satisfied by *sql.DB, *sql.Conn and *sql.Tx.
type PanicSentinel ¶
type PanicSentinel struct { // Cause is the error that caused the panic. Cause error }
PanicSentinel is a wrapper value used to identify panic's that are caused by one of the MustXXX() functions.