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 ¶
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 ¶
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 ¶
Columns calls *sql.Rows.Columns.
type Tx ¶
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 ¶
ExecContext calls *sql.Tx.ExecContext.
func (*Tx) QueryContext ¶
QueryContext calls *sql.Tx.QueryContext.
func (*Tx) QueryRowContext ¶
QueryRowContext calls *sql.Tx.QueryRowContext.