16 unstable releases (6 breaking)

0.7.0 Jan 13, 2021
0.6.0 Nov 14, 2020
0.5.0 Jan 9, 2020
0.4.1 Dec 29, 2019
0.3.0 Nov 30, 2019

#63 in Database implementations

Download history 299/week @ 2020-10-04 336/week @ 2020-10-11 174/week @ 2020-10-18 361/week @ 2020-10-25 340/week @ 2020-11-01 155/week @ 2020-11-08 291/week @ 2020-11-15 256/week @ 2020-11-22 224/week @ 2020-11-29 234/week @ 2020-12-06 133/week @ 2020-12-13 122/week @ 2020-12-20 232/week @ 2020-12-27 276/week @ 2021-01-03 309/week @ 2021-01-10 224/week @ 2021-01-17

989 downloads per month
Used in woddle

MIT/Apache

11KB

mobc-postgres

Build Status crates.io

Documentation

Example

use mobc::Pool;
use std::str::FromStr;
use std::time::Instant;
use mobc_postgres::PgConnectionManager;
use tokio_postgres::Config;
use tokio_postgres::NoTls;


#[tokio::main]
async fn main() {
    let config = Config::from_str("postgres://user:passwd@localhost:5432").unwrap();
    let manager = PgConnectionManager::new(config, NoTls);
    let pool = Pool::builder().max_open(20).build(manager);
    const MAX: usize = 5000;

    let now = Instant::now();
    let (tx, mut rx) = tokio::sync::mpsc::channel::<usize>(16);
    for i in 0..MAX {
        let pool = pool.clone();
        let mut tx_c = tx.clone();
        tokio::spawn(async move {
            let client = pool.get().await.unwrap();
            let rows = client.query("SELECT 1 + 2", &[]).await.unwrap();
            let value: i32 = rows[0].get(0);
            assert_eq!(value, 3);
            tx_c.send(i).await.unwrap();
        });
    }
    for _ in 0..MAX {
        rx.recv().await.unwrap();
    }

    println!("cost: {:?}", now.elapsed());
}

Dependencies

~7MB
~157K SLoC