#async #database #pool #postgres

bin+lib deadpool-postgres

Dead simple async pool for tokio-postgres

4 releases

✓ Uses Rust 2018 edition

new 0.2.3 Dec 2, 2019
0.2.2 Dec 2, 2019
0.2.1 Nov 18, 2019
0.2.0 Nov 14, 2019

#209 in Database interfaces

24 downloads per month

MIT/Apache

21KB
268 lines

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.

Example

use std::env;

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

#[tokio::main]
async fn main() {
    let mut cfg = Config::new();
    cfg.host("/var/run/postgresql");
    cfg.user(env::var("USER").unwrap().as_str());
    cfg.dbname("deadpool");
    let mgr = Manager::new(cfg, tokio_postgres::NoTls);
    let pool = Pool::new(mgr, 16);
    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.

Dependencies

~6MB
~129K SLoC