Struct mysql::Pool [] [src]

pub struct Pool(_);

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.

Example of multithreaded Pool usage:

use mysql::conn::pool;
use std::default::Default;
use mysql::conn::Opts;
use std::thread;

fn get_opts() -> Opts {
      // ...
}

let opts = get_opts();
let pool = pool::Pool::new(opts).unwrap();
let mut threads = Vec::new();
for _ in 0..100 {
    let pool = pool.clone();
    threads.push(thread::spawn(move || {
        let mut result = pool.prep_exec("SELECT 1", ()).unwrap();
        assert_eq!(result.next().unwrap().unwrap().unwrap(), vec![1.into()]);
    }));
}
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

fn new<T: Into<Opts>>(opts: T) -> MyResult<Pool>

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

fn new_manual<T: Into<Opts>>(min: usize, max: usize, opts: T) -> MyResult<Pool>

Same as new but you can set min and max.

fn get_conn(&self) -> MyResult<PooledConn>

Gives you a PooledConn.

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

fn try_get_conn(&self, timeout_ms: u32) -> MyResult<PooledConn>

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.

fn prepare<'a, T: AsRef<str> + 'a>(&'a self, query: T) -> MyResult<Stmt<'a>>

Will prepare statement.

It will try to find connection which has this statement cached.

fn prep_exec<'a, A, T>(&'a self, query: A, params: T) -> MyResult<QueryResult<'a>> where A: AsRef<str>, T: Into<Params>

Shortcut for try!(pool.get_conn()).prep_exec(..).

It will try to find connection which has this statement cached.

fn start_transaction(&self, consistent_snapshot: bool, isolation_level: Option<IsolationLevel>, readonly: Option<bool>) -> MyResult<Transaction>

Shortcut for try!(pool.get_conn()).start_transaction(..).

Trait Implementations

impl Debug for Pool

fn fmt(&self, f: &mut Formatter) -> Result

Derived Implementations

impl Clone for Pool

fn clone(&self) -> Pool

fn clone_from(&mut self, source: &Self)