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 ¶
- Variables
- type Dialect
- type Provider
- func (p *Provider) BeginTx(ctx context.Context, opts *store.TxOptions) (store.Tx, error)
- func (p *Provider) Close() error
- func (p *Provider) DB() *sql.DB
- func (p *Provider) Dialect() dialect.Dialect
- func (p *Provider) ExecContext(ctx context.Context, query string, args ...any) (store.Result, error)
- func (p *Provider) ExplainAnalyze(ctx context.Context, compiled codegen.Compiled) (plan cost.Plan, err error)
- func (p *Provider) Explainer() cost.Explainer
- func (p *Provider) Introspector() introspect.Introspector
- func (p *Provider) PrepareContext(ctx context.Context, query string) (store.Prepared, error)
- func (p *Provider) QueryContext(ctx context.Context, query string, args ...any) (store.Rows, error)
Constants ¶
This section is empty.
Variables ¶
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.
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) Placeholder ¶
func (Dialect) QuoteIdent ¶
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider adapts a PostgreSQL database to the core interfaces.
func New ¶
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 ¶
NewWithTimeout opens PostgreSQL with a DB-native statement timeout.
func (*Provider) DB ¶
DB returns the underlying connection pool, for configuration by the assembler (e.g. SetMaxOpenConns to bound DB connections).
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) Introspector ¶
func (p *Provider) Introspector() introspect.Introspector
Introspector returns the schema introspector.
func (*Provider) PrepareContext ¶
PrepareContext implements store.Preparer.