fsql

package
v1.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package fsql provides database/sql utilities.

Index

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

func WrapDB(db *sql.DB, name string, l *zap.Logger) *DB

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) Close

func (db *DB) Close() error

Close calls *sql.DB.Close.

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

func (db *DB) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

ExecContext calls *sql.DB.ExecContext.

func (*DB) InTransaction added in v1.10.0

func (db *DB) InTransaction(ctx context.Context, f func(*Tx) error) (err error)

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

func (db *DB) QueryContext(ctx context.Context, query string, args ...any) (*Rows, error)

QueryContext calls *sql.DB.QueryContext.

func (*DB) QueryRowContext

func (db *DB) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row

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) Close added in v1.8.0

func (rows *Rows) Close() error

Close calls *sql.Rows.Close.

func (*Rows) Columns added in v1.14.0

func (rows *Rows) Columns() ([]string, error)

Columns calls *sql.Rows.Columns.

func (*Rows) Err added in v1.8.0

func (rows *Rows) Err() error

Err calls *sql.Rows.Err.

func (*Rows) Next added in v1.8.0

func (rows *Rows) Next() bool

Next calls *sql.Rows.Next.

func (*Rows) Scan added in v1.8.0

func (rows *Rows) Scan(dest ...any) error

Scan calls *sql.Rows.Scan.

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) Commit added in v1.10.0

func (tx *Tx) Commit() error

Commit calls *sql.Tx.Commit.

func (*Tx) ExecContext added in v1.10.0

func (tx *Tx) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)

ExecContext calls *sql.Tx.ExecContext.

func (*Tx) QueryContext added in v1.10.0

func (tx *Tx) QueryContext(ctx context.Context, query string, args ...any) (*Rows, error)

QueryContext calls *sql.Tx.QueryContext.

func (*Tx) QueryRowContext added in v1.10.0

func (tx *Tx) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row

QueryRowContext calls *sql.Tx.QueryRowContext.

func (*Tx) Rollback added in v1.10.0

func (tx *Tx) Rollback() error

Rollback calls *sql.Tx.Rollback.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL