Documentation
¶
Overview ¶
Package pgconn opens a Postgres bun.DB from a DSN or from the PG_* environment variables, for callers that do not already have a handle.
Both routes end in one pgdriver.WithDSN call, so the sslmode values accepted are exactly the ones pgdriver accepts, and an unsupported one is an error rather than a silent fallback.
Index ¶
Constants ¶
const ( DefaultHost = "localhost" DefaultPort = "5432" DefaultDatabase = "postgres" )
Defaults for the fields Config leaves empty, matching libpq's.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
DSN string
Host string
Port string
User string
Password string
Database string
SSLMode string
}
Config is where to connect. DSN wins when set; otherwise the other fields are assembled into a postgres:// URL, with User and Password required and the rest defaulting as libpq does. SSLMode is passed through untouched, so the accepted values are pgdriver's: disable, allow, prefer, require, verify-ca and verify-full. Leaving it empty gets pgdriver's default, which is TLS without certificate verification.
func FromEnv ¶
func FromEnv() Config
FromEnv reads DATABASE_URL into DSN and PG_HOST, PG_PORT, PG_USER, PG_PASSWORD, PG_DBNAME and PG_SSLMODE into the other fields. Nothing is validated here; Config.URL and Config.Open report what is missing.