17 releases

0.8.0 Jan 22, 2023
0.7.0 Jan 13, 2021
0.6.0 Nov 14, 2020
0.5.0 Jan 9, 2020
0.3.0 Nov 30, 2019

#75 in #await

Download history 148/week @ 2024-09-01 70/week @ 2024-09-08 86/week @ 2024-09-15 221/week @ 2024-09-22 92/week @ 2024-09-29 25/week @ 2024-10-06 136/week @ 2024-10-13 66/week @ 2024-10-20 91/week @ 2024-10-27 71/week @ 2024-11-03 42/week @ 2024-11-10 89/week @ 2024-11-17 78/week @ 2024-11-24 87/week @ 2024-12-01 201/week @ 2024-12-08 158/week @ 2024-12-15

533 downloads per month
Used in 2 crates

MIT/Apache

13KB

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

~9–19MB
~272K SLoC