Skip to main content

Module pg

Module pg 

Source
Expand description

PostgreSQL driver (feature pg) — sqlx PgPool and PgSqlClient implementing SqlClient.

PgSqlClient::layer is the scoped client layer: it opens the pool when it is built and closes it when its scope closes, providing both SqlClientService and the shared PgPool (PgSqlEnv). Its effects need a tokio runtime with its IO driver (sqlx): run them on id_effect_tokio::TokioRuntime or a TokioExecutor.

§TLS

Connections negotiate TLS through rustls (aws-lc-rs). The mode comes from the URL’s sslmode (with sslrootcert), or from PgPoolConfig::with_tls_mode / PgPoolConfig::with_root_cert_file, which override it. The default, PgTlsMode::Prefer, encrypts when the server offers TLS but checks no certificate and falls back to plaintext, so it does not stop an active attacker: use PgTlsMode::VerifyFull in production.

See docs/platform/adrs/adr-sql-driver-choice.md.

Structs§

PgPool
Shared PostgreSQL pool in the typed environment (derefs to sqlx::PgPool, which is itself a cheap handle: clone it to hand the pool to an adapter).
PgPoolConfig
sqlx PostgreSQL pool sizing, connection string and TLS settings.
PgSqlClient
PostgreSQL SqlClient backed by a sqlx connection pool.
PgSqlError
Driver-local error wrapper (mostly for pool construction).
PgSqlTransaction
PostgreSQL transaction handle: its statements run on the transaction’s connection.

Enums§

PgRootCert
CA certificate(s) a server certificate may chain to (libpq’s sslrootcert).
PgTlsMode
Whether and how a connection negotiates TLS (libpq’s sslmode).

Functions§

pg_pool_from_config
Create a PgPool from config (connects eagerly). A TLS failure (the server refuses TLS under PgTlsMode::Require or stricter, or its certificate does not verify) is SqlError::TlsFailed, an unreachable server SqlError::ConnectionFailed.
pg_pool_from_config_lazy
Lazy pool for unit tests and provider wiring without immediate connect.
provide_pg_pool
A Layer providing pool as the workspace-wide PgPool capability. The pool is not closed by the layer (the caller owns it); see PgSqlClient::layer for a layer that owns its pool.
provide_pg_sql_client
A Layer providing pool as both SqlClientService (a PgSqlClient) and PgPool. It neither checks nor closes the pool (the caller owns it); use PgSqlClient::layer for the scoped variant.

Type Aliases§

PgPoolEnv
The minimal typed environment holding only PgPool.
PgSqlEnv
The environment of the PostgreSQL layers: the client capability and its pool.