postgres

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package postgres adapts a PostgreSQL database to the core interfaces: store.DB/Tx, dialect.Dialect, cost.Explainer, and introspect.Introspector. It is the only place that imports the pgx driver; core packages remain driver-free.

Index

Constants

This section is empty.

Variables

View Source
var ErrAnalyzeRequiresReadOnly = errors.New("postgres: EXPLAIN ANALYZE requires a codegen read-only query")

ErrAnalyzeRequiresReadOnly protects the provider boundary from executing EXPLAIN ANALYZE for statements not marked read-only by codegen.

View Source
var ErrPing = errors.New("postgres: ping failed")

ErrPing is returned when the database is unreachable at open time.

Functions

This section is empty.

Types

type Dialect

type Dialect struct{}

Dialect is the PostgreSQL dialect.

func (Dialect) Capabilities

func (Dialect) Capabilities() dialect.Capabilities

func (Dialect) ExplainSQL

func (Dialect) ExplainSQL(q string) string

func (Dialect) Name

func (Dialect) Name() string

func (Dialect) Placeholder

func (Dialect) Placeholder(i int) string

func (Dialect) QuoteIdent

func (Dialect) QuoteIdent(name string) string

type Provider

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

Provider adapts a PostgreSQL database to the core interfaces.

func New

func New(dsn string) (*Provider, error)

New opens a PostgreSQL database and pings it. The DSN uses the pgx driver format. It returns ErrPing (wrapping the cause) if the database is unreachable, failing fast rather than starting up broken.

func NewWithTimeout

func NewWithTimeout(dsn string, timeout time.Duration) (*Provider, error)

NewWithTimeout opens PostgreSQL with a DB-native statement timeout.

func (*Provider) BeginTx

func (p *Provider) BeginTx(ctx context.Context, opts *store.TxOptions) (store.Tx, error)

BeginTx implements store.TxBeginner.

func (*Provider) Close

func (p *Provider) Close() error

Close closes the underlying connection pool.

func (*Provider) DB

func (p *Provider) DB() *sql.DB

DB returns the underlying connection pool, for configuration by the assembler (e.g. SetMaxOpenConns to bound DB connections).

func (*Provider) Dialect

func (p *Provider) Dialect() dialect.Dialect

Dialect returns the PostgreSQL dialect.

func (*Provider) ExecContext

func (p *Provider) ExecContext(ctx context.Context, query string, args ...any) (store.Result, error)

ExecContext implements store.DB.

func (*Provider) ExplainAnalyze

func (p *Provider) ExplainAnalyze(ctx context.Context, compiled codegen.Compiled) (plan cost.Plan, err error)

ExplainAnalyze implements cost.AnalyzeSampler. EXPLAIN ANALYZE executes the compiled read-only statement once more; callers must apply a separate, tightly bounded sampling context.

func (*Provider) Explainer

func (p *Provider) Explainer() cost.Explainer

Explainer returns the EXPLAIN-based plan estimator.

func (*Provider) Introspector

func (p *Provider) Introspector() introspect.Introspector

Introspector returns the schema introspector.

func (*Provider) PrepareContext

func (p *Provider) PrepareContext(ctx context.Context, query string) (store.Prepared, error)

PrepareContext implements store.Preparer.

func (*Provider) QueryContext

func (p *Provider) QueryContext(ctx context.Context, query string, args ...any) (store.Rows, error)

QueryContext implements store.DB.

Jump to

Keyboard shortcuts

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