fsql

package
v0.0.0-...-bb56650 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2024 License: MIT 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

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

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

func (rows *Rows) Close() error

Close calls *sql.Rows.Close.

func (*Rows) Columns

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

Columns calls *sql.Rows.Columns.

func (*Rows) Err

func (rows *Rows) Err() error

Err calls *sql.Rows.Err.

func (*Rows) Next

func (rows *Rows) Next() bool

Next calls *sql.Rows.Next.

func (*Rows) Scan

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

Scan calls *sql.Rows.Scan.

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

func (tx *Tx) Commit() error

Commit calls *sql.Tx.Commit.

func (*Tx) ExecContext

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

ExecContext calls *sql.Tx.ExecContext.

func (*Tx) QueryContext

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

QueryContext calls *sql.Tx.QueryContext.

func (*Tx) QueryRowContext

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

QueryRowContext calls *sql.Tx.QueryRowContext.

func (*Tx) Rollback

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