Documentation ¶
Overview ¶
Package fsql provides database/sql utilities.
Index ¶
- type DB
- func (db *DB) Close() error
- func (c DB) Collect(ch chan<- prometheus.Metric)
- func (c DB) Describe(ch chan<- *prometheus.Desc)
- func (db *DB) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (db *DB) InTransaction(ctx context.Context, f func(*Tx) error) (err error)
- func (db *DB) QueryContext(ctx context.Context, query string, args ...any) (*Rows, error)
- func (db *DB) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
- type Rows
- type Tx
- func (tx *Tx) Commit() error
- func (tx *Tx) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (tx *Tx) QueryContext(ctx context.Context, query string, args ...any) (*Rows, error)
- func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
- func (tx *Tx) Rollback() error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB wraps *database/sql.DB with tracing, metrics, logging, and resource tracking.
It exposes the subset of *sql.DB methods we use except that it returns *Rows instead of *sql.Rows. It also exposes additional methods.
func WrapDB ¶
WrapDB creates a new DB.
Name is used for metric label values, etc. Logger (that will be named) is used for query logging.
func (DB) Collect ¶
func (c DB) Collect(ch chan<- prometheus.Metric)
Collect implements prometheus.Collector.
func (DB) Describe ¶
func (c DB) Describe(ch chan<- *prometheus.Desc)
Describe implements prometheus.Collector.
func (*DB) ExecContext ¶
ExecContext calls *sql.DB.ExecContext.
func (*DB) InTransaction ¶ added in v1.10.0
InTransaction wraps the given function f in a transaction.
If f returns an error or context is canceled, the transaction is rolled back.
func (*DB) QueryContext ¶
QueryContext calls *sql.DB.QueryContext.
func (*DB) QueryRowContext ¶
QueryRowContext calls *sql.DB.QueryRowContext.
type Rows ¶ added in v1.8.0
type Rows struct {
// contains filtered or unexported fields
}
Rows wraps *database/sql.Rows with resource tracking.
It exposes the subset of *sql.Rows methods we use.
func (*Rows) Columns ¶ added in v1.14.0
Columns calls *sql.Rows.Columns.
type Tx ¶ added in v1.10.0
type Tx struct {
// contains filtered or unexported fields
}
Tx wraps *database/sql.Tx with resource tracking.
It exposes the subset of *sql.Tx methods we use.
func (*Tx) ExecContext ¶ added in v1.10.0
ExecContext calls *sql.Tx.ExecContext.
func (*Tx) QueryContext ¶ added in v1.10.0
QueryContext calls *sql.Tx.QueryContext.
func (*Tx) QueryRowContext ¶ added in v1.10.0
QueryRowContext calls *sql.Tx.QueryRowContext.
func (*Tx) Rollback ¶ added in v1.10.0
Rollback calls *sql.Tx.Rollback.