| Crates.io | pg-client |
| lib.rs | pg-client |
| version | 0.0.1-pre1 |
| created_at | 2025-11-29 05:53:06.615097+00 |
| updated_at | 2025-11-29 05:53:06.615097+00 |
| description | PostgreSQL client configuration and connection management |
| homepage | |
| repository | https://github.com/mbj/mrs/tree/main/pg-client |
| max_upload_size | |
| id | 1956410 |
| size | 104,644 |
Status: Highly experimental - currently only intended for use within pg-ephemeral
A PostgreSQL client configuration library providing strongly-typed connection parameters with accurate representation of PostgreSQL connection options.
sqlx::postgres::PgConnectOptions has several limitations:
PartialEq implementation, making testing difficultpg-client addresses these issues by providing a pure configuration type with complete control over all connection parameters.
All connection parameters use newtype wrappers with validation:
HostName - validated hostname (via hostname-validator)Host - either a hostname or IP address (IPv4/IPv6)HostAddr - explicit IP address for connectionPort - TCP port numberDatabase, Username, ApplicationName - length-validated strings (1-63 bytes, no NUL)Password - length-validated (0-4096 bytes, no NUL)SslMode - all PostgreSQL SSL modes (disable, allow, prefer, require, verify-ca, verify-full)SslRootCert - file path or systemDistinguishes between network and Unix socket connections:
enum Endpoint {
Network { host: Host, host_addr: Option<HostAddr>, port: Option<Port> },
SocketPath(PathBuf),
}
A single Config can be converted to:
to_pg_env()) - PGHOST, PGPORT, PGDATABASE, etc.to_url())sqlx::postgres::PgConnectOptions (to_sqlx_connect_options())When converting to sqlx::postgres::PgConnectOptions, the library detects conflicts between your configuration and environment variables that sqlx would silently infer:
// If PGPASSWORD is set but config.password is None, this returns an error
// rather than silently using the environment value
let options = config.to_sqlx_connect_options()?;
This prevents subtle bugs where environment variables override your intended configuration. The library also rejects unsupported environment variables (PGSSLKEY, PGSSLCERT, PGOPTIONS) that sqlx would pick up.
MIT