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, PgBytesRow, PgConnection, PgDriver, PgDriverBuilder, PgError,
26    PgPool, PgResult, PgRow, PgServerError, PoolConfig, PoolStats, PooledConnection,
27    PreparedAstQuery, QailRow, QueryResult, ReplicationKeepalive, ReplicationOption,
28    ReplicationSlotInfo, ReplicationStreamMessage, ReplicationStreamStart, ReplicationXLogData,
29    ResultFormat, ScopedPoolFuture, ScramChannelBindingMode, TlsConfig, TlsMode, scope,
30    spawn_pool_maintenance,
31};
32pub use protocol::PgEncoder;
33pub use types::{
34    Cidr, Date, FromPg, Inet, Json, MacAddr, Numeric, Time, Timestamp, ToPg, TypeError, Uuid,
35};
36
37/// Generate the RLS SQL string for pipelined execution.
38///
39/// Returns the `BEGIN; SET LOCAL statement_timeout = ...; SELECT set_config(...)`
40/// string that can be passed to `PooledConnection::fetch_all_with_rls()`.
41pub fn rls_sql_with_timeout(ctx: &qail_core::rls::RlsContext, timeout_ms: u32) -> String {
42    driver::rls::context_to_sql_with_timeout(ctx, timeout_ms)
43}
44
45/// Generate the RLS SQL string with both statement and lock timeouts.
46///
47/// When `lock_timeout_ms` is 0, the lock_timeout clause is omitted.
48pub fn rls_sql_with_timeouts(
49    ctx: &qail_core::rls::RlsContext,
50    statement_timeout_ms: u32,
51    lock_timeout_ms: u32,
52) -> String {
53    driver::rls::context_to_sql_with_timeouts(ctx, statement_timeout_ms, lock_timeout_ms)
54}