Skip to main content

giong_postgres/
lib.rs

1//! # giong-postgres
2//!
3//! A PostgreSQL client and connection pool for the [giong] thread-per-core
4//! runtime.
5//!
6//! ```no_run
7//! use giong_postgres::{Client, Config};
8//!
9//! fn main() -> Result<(), giong_postgres::Error> {
10//!     let config = Config::from_url("postgres://app:secret@localhost/shop")?;
11//!     giong::block_on(async {
12//!         let client = Client::connect(&config).await?;
13//!         let rows = client
14//!             .query("SELECT id, name FROM products WHERE price < $1", &[&100i32])
15//!             .await?;
16//!         for row in &rows {
17//!             let id: i64 = row.get("id")?;
18//!             let name: &str = row.get("name")?;
19//!             println!("{id} {name}");
20//!         }
21//!         Ok(())
22//!     })
23//! }
24//! ```
25//!
26//! ## What it does
27//!
28//! * **Pipelining across tasks.** Tasks that share a connection send their
29//!   statements together, and one round trip answers all of them.
30//! * **Prepared statements, kept.** Every statement is prepared the first
31//!   time a connection runs it and kept in a bounded cache, so it takes one
32//!   round trip from then on; parameters and results travel in binary.
33//! * **A pool per worker** ([`Pool`]): no locks, no threads in between;
34//!   statements that stand alone share connections, transactions take one.
35//! * **TLS** through `giong-tls` (rustls), on by default for remote hosts and
36//!   always checking the certificate. **SCRAM-SHA-256** (and MD5, and clear
37//!   text only over TLS or to this machine).
38//! * **Errors that say what to do**, with the server's SQLSTATE code and
39//!   fields in [`DbError`].
40//! * **Limits everywhere**, all finite and documented on [`Config`]: connect
41//!   timeout, statement timeout (enforced by the server), result size,
42//!   statement cache, pool wait.
43//!
44//! ## What it does not do (yet)
45//!
46//! `COPY`, `LISTEN`/`NOTIFY`, streaming rows one at a time, arrays and other
47//! types beyond those listed in [`types`] (read them as strings), channel
48//! binding (`SCRAM-SHA-256-PLUS`), several hosts with failover, and SASLprep
49//! normalization of non-ASCII passwords.
50
51#![warn(missing_docs)]
52
53mod auth;
54mod client;
55mod config;
56mod connect;
57mod error;
58#[cfg(test)]
59mod fuzz_tests;
60mod pool;
61mod protocol;
62mod row;
63pub mod types;
64
65pub use client::{CancelToken, Client, Transaction};
66pub use config::{Config, Tls};
67pub use error::{DbError, Error, ErrorKind};
68pub use pool::{Pool, PoolStats, PooledClient};
69pub use row::{Column, Row, RowIndex};
70pub use types::{FromSql, ToSql, Type};
71
72/// The TLS connector type, re-exported so that [`Tls::Verify`] can be built
73/// without depending on `giong-tls` directly.
74pub use giong_tls::TlsConnector;