Skip to main content

Crate giong_postgres

Crate giong_postgres 

Source
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§

pub use types::FromSql;
pub use types::ToSql;
pub use types::Type;

Modules§

types
Converting between Rust values and PostgreSQL values.

Structs§

CancelToken
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.
PoolStats
What a pool is doing, from Pool::stats.
PooledClient
A connection taken from a Pool with Pool::get. It dereferences to the Client, and goes back to the pool when dropped.
Row
A row of a result.
TlsConnector
The TLS connector type, re-exported so that Tls::Verify can be built without depending on giong-tls directly. 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).

Enums§

ErrorKind
What kind of error it is.
Tls
How the connection is encrypted.

Traits§

RowIndex
A column position or name, for Row::get.