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.

Example of multithreaded MyPool usage:

use mysql::conn::pool;
use std::default::Default;
use mysql::conn::MyOpts;
use mysql::value::ToValue;
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 stmt = pool.prepare("SELECT 1").unwrap();
        let mut result = stmt.execute(&[]).unwrap();
        assert_eq!(result.next().unwrap().unwrap(), vec![1.to_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>>

See docs on Pool#query

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)