Skip to main content

qail_pg/
lib.rs

1//! PostgreSQL driver with AST-native wire encoding.
2//!
3//! **Features:** Zero-alloc encoding, LRU cache (100 max), connection pooling, COPY protocol.
4//!
5//! ```ignore
6//! let mut driver = PgDriver::connect("localhost", 5432, "user", "db").await?;
7//! let rows = driver.fetch_all(&Qail::get("users").limit(10)).await?;
8//! ```
9
10#![deny(deprecated)]
11
12pub mod driver;
13pub mod protocol;
14pub mod types;
15
16pub use driver::explain;
17#[cfg(all(feature = "enterprise-gssapi", target_os = "linux"))]
18pub use driver::gss::{
19    LinuxKrb5PreflightReport, LinuxKrb5ProviderConfig, linux_krb5_preflight,
20    linux_krb5_token_provider,
21};
22pub use driver::{
23    AstPipelineMode, AuthSettings, AutoCountPath, AutoCountPlan, ConnectOptions,
24    EnterpriseAuthMechanism, GssEncMode, GssTokenProvider, GssTokenProviderEx, GssTokenRequest,
25    IdentifySystem, Notification, PgConnection, PgDriver, PgDriverBuilder, PgError, PgPool,
26    PgResult, PgRow, PgServerError, PoolConfig, PoolStats, PooledConnection, PreparedAstQuery,
27    QailRow, QueryResult, ReplicationKeepalive, ReplicationOption, ReplicationSlotInfo,
28    ReplicationStreamMessage, ReplicationStreamStart, ReplicationXLogData, ResultFormat,
29    ScopedPoolFuture, ScramChannelBindingMode, TlsConfig, TlsMode, scope, spawn_pool_maintenance,
30};
31pub use protocol::PgEncoder;
32pub use types::{
33    Cidr, Date, FromPg, Inet, Json, MacAddr, Numeric, Time, Timestamp, ToPg, TypeError, Uuid,
34};
35
36/// Generate the RLS SQL string for pipelined execution.
37///
38/// Returns the `BEGIN; SET LOCAL statement_timeout = ...; SELECT set_config(...)`
39/// string that can be passed to `PooledConnection::fetch_all_with_rls()`.
40pub fn rls_sql_with_timeout(ctx: &qail_core::rls::RlsContext, timeout_ms: u32) -> String {
41    driver::rls::context_to_sql_with_timeout(ctx, timeout_ms)
42}
43
44/// Generate the RLS SQL string with both statement and lock timeouts.
45///
46/// When `lock_timeout_ms` is 0, the lock_timeout clause is omitted.
47pub fn rls_sql_with_timeouts(
48    ctx: &qail_core::rls::RlsContext,
49    statement_timeout_ms: u32,
50    lock_timeout_ms: u32,
51) -> String {
52    driver::rls::context_to_sql_with_timeouts(ctx, statement_timeout_ms, lock_timeout_ms)
53}