heliosdb_proxy/backend/mod.rs
1//! Backend PostgreSQL client used by TR-management code paths.
2//!
3//! `ProxyServer::route_and_forward` still forwards client frames to
4//! backends without ever parsing or originating SQL — that zero-copy
5//! path remains untouched. This module is the *other* direction: the
6//! proxy itself acts as a PG client for internal management queries
7//! (health checks, `pg_is_in_recovery()`, `pg_promote()`, WAL-position
8//! probes, failover replay, session-state restoration).
9//!
10//! Design goals:
11//!
12//! * **No `tokio-postgres`.** We reuse `crate::protocol` for every
13//! wire frame so the crate has exactly one PG protocol
14//! implementation.
15//! * **TLS-capable.** `tls::negotiate` performs the `SSLRequest`
16//! dance and wraps the TCP stream in `tokio-rustls` when accepted.
17//! * **Text format only.** All parameter values are interpolated as
18//! quoted SQL literals before send; extended-protocol
19//! Parse/Bind/Execute is deliberately out of scope for internal
20//! management queries.
21//! * **Narrow type surface.** Seven OIDs — BOOL, INT4, INT8, TEXT,
22//! FLOAT8, TIMESTAMPTZ, NUMERIC — plus PG_LSN for WAL positions.
23//!
24//! # Example
25//!
26//! ```no_run
27//! use heliosdb_proxy::backend::{BackendClient, BackendConfig, tls, TlsMode};
28//! use std::time::Duration;
29//!
30//! # async fn f() -> heliosdb_proxy::backend::BackendResult<()> {
31//! let cfg = BackendConfig {
32//! host: "primary.db.internal".into(),
33//! port: 5432,
34//! user: "postgres".into(),
35//! password: Some("secret".into()),
36//! database: Some("app".into()),
37//! application_name: Some("helios-health".into()),
38//! tls_mode: TlsMode::Prefer,
39//! connect_timeout: Duration::from_secs(5),
40//! query_timeout: Duration::from_secs(5),
41//! tls_config: tls::default_client_config(),
42//! };
43//! let mut c = BackendClient::connect(&cfg).await?;
44//! let in_recovery = c.query_scalar("SELECT pg_is_in_recovery()").await?;
45//! # Ok(())
46//! # }
47//! ```
48
49pub mod auth;
50pub mod client;
51pub mod error;
52pub mod stream;
53pub mod tls;
54pub mod types;
55
56pub use client::{BackendClient, BackendConfig, ColumnMeta, QueryResult};
57pub use error::{BackendError, BackendResult};
58pub use stream::Stream;
59pub use tls::TlsMode;
60pub use types::{encode_literal, oid, ParamValue, TextValue};