Documentation
¶
Overview ¶
Package postgres connects github.com/go-rio/rio to PostgreSQL through the pgx driver's database/sql adapter.
The package is deliberately thin: it constructs a *rio.DB with the built-in rio.Postgres dialect, installs a precise error translator that maps *pgconn.PgError values onto rio's sentinel errors, and keeps the connection settings honest about standard_conforming_strings. All SQL grammar lives in the rio core; this module never shapes a query.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
New wraps an existing *sql.DB in a *rio.DB with the Postgres dialect and this package's error translator. Use it when you bring your own pool: a *sql.DB you tuned yourself, or one derived from a pgxpool.Pool via stdlib.OpenDBFromPool.
New performs no connection hygiene — the pool is the caller's; make sure its sessions run with standard_conforming_strings on (the server default since PostgreSQL 9.1), or rio's placeholder rewriting can disagree with the server's lexing (see Open).
Options are applied after the translator, so rio.WithErrorTranslator in opts replaces this package's translation if you need to.
func Open ¶
Open opens a PostgreSQL database via pgx's database/sql adapter and wraps it in a *rio.DB. The DSN is handed to pgx untouched, so both URL form (postgres://user:pass@host:5432/app) and keyword/value form (host=... user=... dbname=...) work, along with every pgx runtime parameter — except one.
rio rewrites ? placeholders by lexing the SQL with standard_conforming_strings on, the server default since PostgreSQL 9.1: a backslash inside a '...' literal is an ordinary character. A session running with the setting off lexes those literals differently — backslash escapes again — so the server could disagree with rio about which ? are placeholders. Open therefore rejects a configuration that turns the setting off, whether spelled as a runtime parameter (standard_conforming_strings=off) or inside the options startup parameter (options=-c standard_conforming_strings=off — including one pgx inherits from the PGOPTIONS environment variable). An explicit on passes through, and when the setting is never mentioned nothing is injected: Open never connects, so it cannot see the server's value. If your server turns the setting off globally, turn it back on for rio's connections in the DSN — the README shows a paste-ready example.
Open validates the DSN eagerly — pgx's database/sql adapter would otherwise surface a malformed DSN on the first query — but it does not connect; ping the underlying pool (db.Unwrap().PingContext) to verify connectivity. Pool tuning also happens on the *sql.DB returned by Unwrap — rio never replaces or configures the connection pool.
Types ¶
This section is empty.