Documentation
¶
Overview ¶
Package db provides Postgres connectivity for the application: a pooled connection built from configuration and a health check used for readiness.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ApplySSLRootCert ¶
ApplySSLRootCert injects the sslrootcert parameter into the connection string and forces sslmode=verify-full. A CA bundle is only meaningful under full verification: sslmode=require encrypts but skips CA and hostname checks, so supplying a root cert without verify-full would be a false sense of security. pgx then loads the CA bundle and verifies the server certificate and hostname. URL-form DSNs (the project default and what Supabase hands out) are parsed and re-encoded; keyword/value DSNs get the parameters appended (later keys win, so the appended sslmode overrides any earlier one). Exported so callers that run their own connection (e.g. the migration runner) normalize the DSN identically to the pool.
func Health ¶
Health verifies live connectivity by acquiring a connection and pinging it. It backs the HTTP readiness check (route registered by the HTTP server) and returns a non-nil error when the database is unreachable.
Types ¶
type Option ¶ added in v0.2.0
Option customizes the pgxpool.Config New builds, beyond what DBConfig itself expresses.
func WithSearchPath ¶ added in v0.2.0
WithSearchPath sets the pool's default search_path to schemas, applied as a connection runtime parameter so every connection the pool opens starts with it. Pass the caller's own schema first, then any schema it should reach unqualified beyond that (typically the shared identity schema). Schema-qualified SQL remains legal regardless — this only changes what an UNQUALIFIED name resolves to, it is a default, not an access restriction. No schemas is a no-op, not an empty search path — see below.
Setting search_path this way REPLACES Postgres's own default ("$user", public) rather than extending it: a caller whose own tables still live in public must include "public" explicitly or unqualified references to them will stop resolving.
search_path is SESSION state, delivered here as a connection startup parameter. Under DB_POOL_MODE=transaction (see applySupabasePooling) the pooler multiplexes a backend connection per transaction, so confirm the pooler propagates search_path before relying on this option there — otherwise schema-qualify instead, since a search_path that silently fails to apply resolves unqualified names against the wrong schema rather than erroring.
type TX ¶
type TX interface {
Exec(ctx context.Context, sql string, args ...any) (pgconn.CommandTag, error)
Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)
QueryRow(ctx context.Context, sql string, args ...any) pgx.Row
}
TX is the minimal query surface shared by *pgxpool.Pool and pgx.Tx. Adapters depend on this interface (instead of the concrete pool) so the same repository code runs both directly against the pool and inside a transaction: a transactional caller constructs a repository with a pgx.Tx, while the default composition uses the pool. Both concrete types satisfy TX unchanged.
It is named TX (not DBTX) to avoid the db.DBTX stutter; "db.TX" reads as "a database transaction-capable executor".
Directories
¶
| Path | Synopsis |
|---|---|
|
Package dbtest provides the shared harness for database-gated tests.
|
Package dbtest provides the shared harness for database-gated tests. |
|
Package migrate runs database schema migrations with goose over the pgx stdlib driver (a database/sql handle, distinct from an application's pgxpool).
|
Package migrate runs database schema migrations with goose over the pgx stdlib driver (a database/sql handle, distinct from an application's pgxpool). |