[][src]Crate deadpool_postgres

Deadpool for PostgreSQL Latest Version

Deadpool is a dead simple async pool for connections and objects of any type.

This crate implements a deadpool manager for tokio-postgres and also provides a statement cache by wrapping tokio_postgres::Client and tokio_postgres::Transaction.

Features

FeatureDescriptionExtra dependenciesDefault
configEnable support for config crateconfig, serde/deriveyes

Example

use deadpool_postgres::{Config, Manager, Pool};
use tokio_postgres::{NoTls};

#[tokio::main]
async fn main() {
    let mut cfg = Config::from_env("PG").unwrap();
    let pool = cfg.create_pool(NoTls).unwrap();
    for i in 1..10 {
        let mut client = pool.get().await.unwrap();
        let stmt = client.prepare("SELECT 1 + $1").await.unwrap();
        let rows = client.query(&stmt, &[&i]).await.unwrap();
        let value: i32 = rows[0].get(0);
        assert_eq!(value, i + 1);
    }
}

License

Licensed under either of

at your option.

Re-exports

pub use crate::config::Config;

Modules

config

This module describes configuration used for Pool creation.

Structs

ClientWrapper

A wrapper for tokio_postgres::Client which includes a statement cache.

Manager

The manager for creating and recyling postgresql connections

StatementCache

This structure holds the cached statements and provides access to functions for retrieving the current size and clearing the cache.

Transaction

A wrapper for tokio_postgres::Transaction which uses the statement cache from the client object it was created by.

Type Definitions

Client

A type alias for using deadpool::Object with tokio_postgres

Pool

A type alias for using deadpool::Pool with tokio_postgres

PoolError

A type alias for using deadpool::PoolError with tokio_postgres