driver

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const Source = "postgresql"

Source is the value reported in the Source field of an api.NormalizedError for errors originating from this driver. The driver only supports Postgres, so this is constant.

Variables

View Source
var ErrMultiStatement = errors.New("cannot run multiple statements in a single query")

Functions

This section is empty.

Types

type Columns

type Columns []api.Column

Columns is a slice of Column types, with some additional convenience methods.

func (Columns) ScanTargets

func (c Columns) ScanTargets() ScanTargets

ScanTargets returns a slice of types suitable for passing to [Rows.Scan].

func (Columns) ScanTypes

func (c Columns) ScanTypes() []reflect.Type

ScanTypes returns a reflect.Type slice representing the Go types into which column values should be scanned.

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver executes arbitrary SQL queries against a Postgres database instance. It wraps sql.DB and sql.Conn and provides additional methods for normalizing query results and errors.

func Open

func Open(ctx context.Context, dsn string) (d *Driver, err error)

Open establishes a new Postgres Driver connection using the provided DSN. It opens the connection pool, acquires a single dedicated connection, and wires up the query tracer and cancellation handler. If an error occurs after a resource is acquired, that resource is closed before returning.

func (*Driver) Close

func (d *Driver) Close() error

Close waits for all in-progress queries to finish before closing the underlying database connection and pool.

func (*Driver) NormalizeError

func (d *Driver) NormalizeError(ctx context.Context, err error) *api.NormalizedError

NormalizeError normalizes an error returned from the database driver. The returned error also carries information about whether the query was canceled, timed out, or executed on a broken database connection.

func (*Driver) Ping

func (d *Driver) Ping(ctx context.Context) error

Ping checks whether the underlying database connection is alive, returning an error if not. It is not safe to call concurrently with itself or Query.

func (*Driver) Query

func (d *Driver) Query(ctx context.Context, query string) (*Rows, error)

Query issues an SQL query and returns the results. Canceling the passed-in context cancels the in-progress query via the connection's context-watcher handler. It is not safe to call concurrently with itself or Ping.

type Rows

type Rows struct {
	*sql.Rows
	// contains filtered or unexported fields
}

Rows is the result of running a query. It embeds sql.Rows for iteration/scanning (Next, Scan, Err, Close) and adds methods for column metadata and the number of rows affected, the latter sourced from the query tracer.

func (*Rows) Columns

func (r *Rows) Columns() (Columns, error)

Columns returns information about the query result columns being returned, including their names, types, and other column metadata. It also identifies the Go type into which column values should be scanned.

func (*Rows) RowsAffected

func (r *Rows) RowsAffected(ctx context.Context) (*int64, error)

RowsAffected returns the number of rows affected by the query (e.g. for INSERT/UPDATE/DELETE statements), if available. Returns nil if the number of rows affected is not available. For SELECT statements and other statements that return rows, it may return the resulting row count. Note that this method may return nil if called before the query has completed. It is typically best to wait until the rows iterator has been closed before calling it.

type ScanTargets

type ScanTargets []any

ScanTargets represents a slice of types that can be passed to [Rows.Scan] to scan column values from the database, for a given set of query results.

func (ScanTargets) Values

func (s ScanTargets) Values() []any

Values returns the row values that have been scanned into ScanTargets after a call to [Rows.Scan].

Jump to

Keyboard shortcuts

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