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 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). |