Documentation
¶
Index ¶
Constants ¶
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 ¶
var ErrMultiStatement = errors.New("cannot run multiple statements in a single query")
Functions ¶
This section is empty.
Types ¶
type Columns ¶
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].
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 ¶
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 ¶
Close waits for all in-progress queries to finish before closing the underlying database connection and pool.
func (*Driver) NormalizeError ¶
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 ¶
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.
type Rows ¶
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 ¶
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 ¶
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].