Expand description
§giong-postgres
A PostgreSQL client and connection pool for the giong thread-per-core runtime.
use giong_postgres::{Client, Config};
fn main() -> Result<(), giong_postgres::Error> {
let config = Config::from_url("postgres://app:secret@localhost/shop")?;
giong::block_on(async {
let client = Client::connect(&config).await?;
let rows = client
.query("SELECT id, name FROM products WHERE price < $1", &[&100i32])
.await?;
for row in &rows {
let id: i64 = row.get("id")?;
let name: &str = row.get("name")?;
println!("{id} {name}");
}
Ok(())
})
}§What it does
- Pipelining across tasks. Tasks that share a connection send their statements together, and one round trip answers all of them.
- Prepared statements, kept. Every statement is prepared the first time a connection runs it and kept in a bounded cache, so it takes one round trip from then on; parameters and results travel in binary.
- A pool per worker (
Pool): no locks, no threads in between; statements that stand alone share connections, transactions take one. - TLS through
giong-tls(rustls), on by default for remote hosts and always checking the certificate. SCRAM-SHA-256 (and MD5, and clear text only over TLS or to this machine). - Errors that say what to do, with the server’s SQLSTATE code and
fields in
DbError. - Limits everywhere, all finite and documented on
Config: connect timeout, statement timeout (enforced by the server), result size, statement cache, pool wait.
§What it does not do (yet)
COPY, LISTEN/NOTIFY, streaming rows one at a time, arrays and other
types beyond those listed in types (read them as strings), channel
binding (SCRAM-SHA-256-PLUS), several hosts with failover, and SASLprep
normalization of non-ASCII passwords.
Re-exports§
Modules§
- types
- Converting between Rust values and PostgreSQL values.
Structs§
- Cancel
Token - Asks the server to cancel what a connection is running.
- Client
- A connection to a PostgreSQL server.
- Column
- A column of a result.
- Config
- Connection settings: where the server is, who to log in as, and the limits that apply to the connection.
- DbError
- An error reported by the server, with the fields of its
ErrorResponse. - Error
- An error from giong-postgres.
- Pool
- Connections to one server, for the tasks of one worker thread.
- Pool
Stats - What a pool is doing, from
Pool::stats. - Pooled
Client - A connection taken from a
PoolwithPool::get. It dereferences to theClient, and goes back to the pool when dropped. - Row
- A row of a result.
- TlsConnector
- The TLS connector type, re-exported so that
Tls::Verifycan be built without depending ongiong-tlsdirectly. Opens TLS connections to servers, checking their certificates. - Transaction
- An open transaction. Statements run through it with the same methods as
on
Client(it dereferences to the client).