Skip to main content

qail_pg/
lib.rs

1//! QAIL Postgres Driver.
2//!
3//! `qail-pg` executes `qail-core` AST commands through the native PostgreSQL
4//! wire protocol. It owns connection I/O, TLS, authentication, pooling,
5//! prepared AST execution, pipeline execution, COPY, LISTEN/NOTIFY, and
6//! PostgreSQL type conversion.
7//!
8//! The normal application path is:
9//!
10//! ```text
11//! qail_core::Qail AST -> qail_pg::PgDriver/PgPool -> PostgreSQL wire protocol
12//! ```
13//!
14//! SQL text may still appear in debugging, EXPLAIN output, or server-side
15//! PostgreSQL parse/plan behavior, but application code should build `Qail`
16//! commands instead of concatenating SQL strings.
17//!
18//! ```ignore
19//! use qail_core::prelude::*;
20//! use qail_pg::PgDriver;
21//!
22//! let mut driver = PgDriver::connect("localhost", 5432, "user", "db").await?;
23//! let cmd = Qail::get("users").columns(["id", "email"]).limit(10);
24//! let rows = driver.fetch_all(&cmd).await?;
25//! ```
26
27#![deny(deprecated)]
28
29pub mod driver;
30pub mod protocol;
31pub mod types;
32
33pub use driver::explain;
34#[cfg(all(feature = "enterprise-gssapi", target_os = "linux"))]
35pub use driver::gss::{
36    LinuxKrb5PreflightReport, LinuxKrb5ProviderConfig, linux_krb5_preflight,
37    linux_krb5_token_provider,
38};
39pub use driver::{
40    AstPipelineMode, AuthSettings, AutoCountPath, AutoCountPlan, ConnectOptions,
41    EnterpriseAuthMechanism, GssEncMode, GssTokenProvider, GssTokenRequest, IdentifySystem,
42    Notification, PgBytesRow, PgConnection, PgDriver, PgDriverBuilder, PgError, PgPool, PgResult,
43    PgRow, PgServerError, PoolConfig, PoolStats, PooledConnection, PreparedAstQuery, QailRow,
44    QueryResult, ReplicationKeepalive, ReplicationOption, ReplicationSlotInfo,
45    ReplicationStreamMessage, ReplicationStreamStart, ReplicationXLogData, ResultFormat,
46    ScopedPoolFuture, ScramChannelBindingMode, TlsConfig, TlsMode, scope, spawn_pool_maintenance,
47};
48pub use protocol::PgEncoder;
49pub use types::{
50    Cidr, Date, FromPg, Inet, Json, MacAddr, Numeric, Time, Timestamp, ToPg, TypeError, Uuid,
51};
52
53/// Generate the RLS SQL string for pipelined execution.
54///
55/// Returns the `BEGIN; SET LOCAL statement_timeout = ...; SELECT set_config(...)`
56/// string that can be passed to `PooledConnection::fetch_all_with_rls()`.
57pub fn rls_sql_with_timeout(ctx: &qail_core::rls::RlsContext, timeout_ms: u32) -> String {
58    driver::rls::context_to_sql_with_timeout(ctx, timeout_ms)
59}
60
61/// Generate the RLS SQL string with both statement and lock timeouts.
62///
63/// When `lock_timeout_ms` is 0, the lock_timeout clause is omitted.
64pub fn rls_sql_with_timeouts(
65    ctx: &qail_core::rls::RlsContext,
66    statement_timeout_ms: u32,
67    lock_timeout_ms: u32,
68) -> String {
69    driver::rls::context_to_sql_with_timeouts(ctx, statement_timeout_ms, lock_timeout_ms)
70}