mobc-postgres

Compatibility

tokio-postgres is built with tokio 0.2, and it can't run in the Runtime built with async-std, if you do, you will get an error from tokio which is Custom { kind: Other, error: "no current reactor" }.

Examples

```rust use mobc::futures::channel::mpsc; use mobc::futures::prelude::*; use mobc::runtime::DefaultExecutor; use mobc::Error; use mobc::Pool; use mobcpostgres::tokiopostgres; use mobcpostgres::PostgresConnectionManager; use std::str::FromStr; use std::time::Instant; use tokiopostgres::Config; use tokiopostgres::Error as PostgresError; use tokiopostgres::NoTls;

const MAX: usize = 5000;

async fn simplequery( pool: Pool>, mut sender: mpsc::Sender<()>, ) -> Result<(), Error> { let conn = pool.get().await?; let r = conn.execute("SELECT 1", &[]).await?; asserteq!(r, 1); sender.send(()).await.unwrap(); Ok(()) }

async fn dopostgres(sender: mpsc::Sender<()>) -> Result<(), Error> { let config = Config::fromstr("postgres://jiaju:jiaju@localhost:5432")?; let manager = PostgresConnectionManager::new(config, NoTls); let pool = Pool::new(manager).await?;

for _ in 0..MAX {
    let pool = pool.clone();
    let tx = sender.clone();
    tokio::spawn(simple_query(pool, tx).map(|_| ()));
}

Ok(())

}

[tokio::main]

async fn main() { env_logger::init(); let mark = Instant::now(); let (tx, mut rx) = mpsc::channel::<()>(MAX);

do_postgres(tx).await.unwrap();

let mut num: usize = 0;
while let Some(_) = rx.next().await {
    num += 1;
    if num == MAX {
        break;
    }
}

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

}

```