[][src]Struct orma_mobc::PgConnectionManager

pub struct PgConnectionManager<Tls> { /* fields omitted */ }

A mobc::Manager for orma::Connections. This crate is a strict derivation of mobc-postgres

Example

use mobc::Pool;
use orma_mobc::PgConnectionManager;
use orma::{Config, NoTls};
use std::time::Instant;
use std::str::FromStr;
#[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 connection = pool.get().await.unwrap();
            let rows = connection.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());
}

Methods

impl<Tls> PgConnectionManager<Tls>[src]

pub fn new(config: Config, tls: Tls) -> Self[src]

Trait Implementations

impl<Tls> Manager for PgConnectionManager<Tls> where
    Tls: MakeTlsConnect<Socket> + Clone + Send + Sync + 'static,
    <Tls as MakeTlsConnect<Socket>>::Stream: Send + Sync,
    <Tls as MakeTlsConnect<Socket>>::TlsConnect: Send,
    <<Tls as MakeTlsConnect<Socket>>::TlsConnect as TlsConnect<Socket>>::Future: Send
[src]

type Connection = Connection

The connection type this manager deals with.

type Error = DbError

The error type returned by Connections.

Auto Trait Implementations

impl<Tls> RefUnwindSafe for PgConnectionManager<Tls> where
    Tls: RefUnwindSafe

impl<Tls> Send for PgConnectionManager<Tls> where
    Tls: Send

impl<Tls> Sync for PgConnectionManager<Tls> where
    Tls: Sync

impl<Tls> Unpin for PgConnectionManager<Tls> where
    Tls: Unpin

impl<Tls> UnwindSafe for PgConnectionManager<Tls> where
    Tls: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,