Documentation ¶
Overview ¶
Package tagsql implements a tagged wrapper for databases.
This package also handles hides context cancellation from database drivers that don't support it.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn interface { BeginTx(ctx context.Context, txOptions *sql.TxOptions) (Tx, error) Close() error ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) PingContext(ctx context.Context) error PrepareContext(ctx context.Context, query string) (Stmt, error) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row Raw(ctx context.Context, f func(driverConn interface{}) error) (err error) }
Conn is an interface for *sql.Conn-like connections.
func ConnWithoutTxContext ¶
ConnWithoutTxContext wraps *sql.Conn.
type ContextSupport ¶
type ContextSupport byte
ContextSupport returns the level of context support a driver has.
const ( SupportBasic ContextSupport = 1 << 0 SupportTransactions ContextSupport = 1 << 1 SupportNone ContextSupport = 0 SupportAll ContextSupport = SupportBasic | SupportTransactions )
Constants for defining context level support.
func DetectContextSupport ¶
func DetectContextSupport(db *sql.DB) (ContextSupport, error)
DetectContextSupport detects *sql.DB driver without importing the specific packages.
func (ContextSupport) Basic ¶
func (v ContextSupport) Basic() bool
Basic returns true when driver supports basic contexts.
func (ContextSupport) Transactions ¶
func (v ContextSupport) Transactions() bool
Transactions returns true when driver supports contexts inside transactions.
type DB ¶
type DB interface { // To be deprecated, the following take ctx as argument, // however do not pass it forward to the underlying database. Begin(ctx context.Context) (Tx, error) Driver() driver.Driver Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error) Ping(ctx context.Context) error Prepare(ctx context.Context, query string) (Stmt, error) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row BeginTx(ctx context.Context, txOptions *sql.TxOptions) (Tx, error) Conn(ctx context.Context) (Conn, error) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) PingContext(ctx context.Context) error PrepareContext(ctx context.Context, query string) (Stmt, error) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row Close() error SetConnMaxLifetime(d time.Duration) SetMaxIdleConns(n int) SetMaxOpenConns(n int) Stats() sql.DBStats Internal() *sql.DB }
DB implements a wrapper for *sql.DB-like database.
The wrapper adds tracing to all calls. It also adds context handling compatibility for different databases.
func AllowContext ¶
AllowContext turns a *sql.DB into a DB which uses context calls.
func WithoutContext ¶
WithoutContext turns a *sql.DB into a DB-matching that redirects context calls to regular calls.
type Stmt ¶
type Stmt interface { // Exec and other methods take a context for tracing // purposes, but do not pass the context to the underlying database query. Exec(ctx context.Context, args ...interface{}) (sql.Result, error) Query(ctx context.Context, args ...interface{}) (*sql.Rows, error) QueryRow(ctx context.Context, args ...interface{}) *sql.Row // ExecContext and other Context methods take a context for tracing and also // pass the context to the underlying database, if this tagsql instance is // configured to do so. (By default, lib/pq does not ever, and // mattn/go-sqlite3 does not for transactions). ExecContext(ctx context.Context, args ...interface{}) (sql.Result, error) QueryContext(ctx context.Context, args ...interface{}) (*sql.Rows, error) QueryRowContext(ctx context.Context, args ...interface{}) *sql.Row Close() error }
Stmt is an interface for *sql.Stmt.
type Tx ¶
type Tx interface { // Exec and other methods take a context for tracing // purposes, but do not pass the context to the underlying database query Exec(ctx context.Context, query string, args ...interface{}) (sql.Result, error) Prepare(ctx context.Context, query string) (Stmt, error) Query(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRow(ctx context.Context, query string, args ...interface{}) *sql.Row // ExecContext and other Context methods take a context for tracing and also // pass the context to the underlying database, if this tagsql instance is // configured to do so. (By default, lib/pq does not ever, and // mattn/go-sqlite3 does not for transactions). ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error) PrepareContext(ctx context.Context, query string) (Stmt, error) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row Commit() error Rollback() error }
Tx is an interface for *sql.Tx-like transactions.