[][src]Struct mysql::Pool

pub struct Pool { /* fields omitted */ }

Pool serves to provide you with a PooledConn's. However you can prepare statements directly on Pool without invoking Pool::get_conn.

Pool will hold at least min connections and will create as many as max connections with possible overhead of one connection per alive thread.

Example of multithreaded Pool usage:

let opts = get_opts();
let pool = Pool::new(opts).unwrap();
let mut threads = Vec::new();

for _ in 0..100 {
    let pool = pool.clone();
    threads.push(std::thread::spawn(move || {
        let mut conn = pool.get_conn().unwrap();
        let result: u8 = conn.query_first("SELECT 1").unwrap().unwrap();
        assert_eq!(result, 1_u8);
    }));
}

for t in threads.into_iter() {
    assert!(t.join().is_ok());
}

For more info on how to work with mysql connection please look at PooledConn documentation.

Methods

impl Pool[src]

pub fn new<T: Into<Opts>>(opts: T) -> Result<Pool>[src]

Creates new pool with min = 10 and max = 100.

pub fn new_manual<T: Into<Opts>>(
    min: usize,
    max: usize,
    opts: T
) -> Result<Pool>
[src]

Same as new but you can set min and max.

pub fn use_cache(&mut self, use_cache: bool)[src]

A way to turn off searching for cached statement (on by default).

If turned on, then calls to Pool::{prepare, prep_exec, first_exec} will search for cached statement through all connections in the pool. Useless if the value of the stmt_cache_size option is 0.

pub fn check_health(&mut self, check_health: bool)[src]

A way to turn off connection health check on each call to get_conn and prepare (prep_exec is not affected) (on by default).

pub fn get_conn(&self) -> Result<PooledConn>[src]

Gives you a PooledConn.

Pool will check that connection is alive via Conn::ping and will call Conn::reset if necessary.

pub fn try_get_conn(&self, timeout_ms: u32) -> Result<PooledConn>[src]

Will try to get connection for a duration of timeout_ms milliseconds.

Failure

This function will return Error::DriverError(DriverError::Timeout) if timeout was reached while waiting for new connection to become available.

pub fn start_transaction(&self, tx_opts: TxOpts) -> Result<Transaction<'static>>[src]

Shortcut for pool.get_conn()?.start_transaction(..).

Trait Implementations

impl Clone for Pool[src]

impl Debug for Pool[src]

Auto Trait Implementations

impl !RefUnwindSafe for Pool

impl Send for Pool

impl Sync for Pool

impl Unpin for Pool

impl !UnwindSafe for Pool

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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>,