Struct mysql::conn::pool::MyPool [] [src]

pub struct MyPool {
    // some fields omitted
}

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

MyPool will hold at least min connections and will create as many as max connections.

Example of multithreaded MyPool usage:

use mysql::conn::pool;
use std::default::Default;
use mysql::conn::MyOpts;
use mysql::value::IntoValue;
use std::thread;

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

let opts = get_opts();
let pool = pool::MyPool::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(), vec![1.into_value()]);
    }));
}
for t in threads.into_iter() {
    assert!(t.join().is_ok());
}

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

Methods

impl MyPool

fn new(opts: MyOpts) -> MyResult<MyPool>

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

fn new_manual(min: usize, max: usize, opts: MyOpts) -> MyResult<MyPool>

Same as new but you can set min and max.

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

Gives you a MyPooledConn.

MyPool will check that connection is alive via MyConn::ping and will call MyConn::reset if necessary.

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: AsRef<str>, T: ToRow>(&'a self, query: A, params: T) -> MyResult<QueryResult<'a>>

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

Derived Implementations

impl Debug for MyPool

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

impl Clone for MyPool

fn clone(&self) -> MyPool

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