Documentation
¶
Overview ¶
Package driverpgx opens Postgres databases for github.com/ubgo/sqlb.
It is a separate Go module inside the sqlb repository for the reason every contrib module is: the core depends on nothing but the standard library, so a library that embeds it inherits no driver. A driver is a dependency, so it lives out here, and an application pays for it only by importing this module.
The module's real work is its tests. The pg package holds five hundred exported constructs and, until this module existed, not one of them had run against a Postgres server: rendered text was checked and nothing else. A comparison with another Go builder showed exactly what that hides — a table declared without an alias rendered a quoted empty identifier, which SQLite accepts and Postgres rejects, so every test stayed green while the SQL was invalid on the engine the package is named after. This module runs the shared conformance suite and executes the pg constructs against a real server, which is the only thing that turns an asserted construct into a proven one.
The driver is github.com/jackc/pgx/v5 through its database/sql adapter, so exec.DBTX is satisfied by *sql.DB and *sql.Tx exactly as it is for SQLite.
Index ¶
Constants ¶
const ( // DefaultMaxOpenConns caps the pool. Postgres connections are processes // on the server, so an uncapped pool under load exhausts the server's // max_connections before it exhausts anything on the client. DefaultMaxOpenConns = 8 // DefaultConnMaxLifetime recycles connections so a server restart or a // pooler in front of it does not leave the pool holding dead sockets. DefaultConnMaxLifetime = 30 * time.Minute )
Defaults applied to every pool Open creates. They are the settings a process whose libraries own tables wants, and each is overridable.
const DriverName = "pgx"
DriverName is the database/sql name the pgx stdlib adapter registers.
const EnvDSN = "SQLB_PG_DSN"
EnvDSN is the environment variable the tests read the connection string from. Absence is a loud skip, never a silent pass: a test that needs a server and has none says so in its output rather than reporting success for work it did not do.
Variables ¶
This section is empty.
Functions ¶
func DSNFromEnv ¶
DSNFromEnv returns the connection string the tests use, and false when it is not set. It is exported so a consumer's own integration tests can share the convention.
Types ¶
type Option ¶
type Option func(*config)
Option adjusts what Open does.
func WithConnMaxLifetime ¶
WithConnMaxLifetime sets how long a connection may be reused.
func WithMaxOpenConns ¶
WithMaxOpenConns caps the pool at n connections.