[][src]Struct c3p0_mysql::mysql::driver::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:

use mysql::{Pool, Opts};
use std::thread;

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

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(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[src]

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

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

pub fn new_manual<T>(min: usize, max: usize, opts: T) -> Result<Pool, Error> where
    T: Into<Opts>, 
[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, Error>[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, Error>[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 prepare<T>(&self, query: T) -> Result<Stmt<'static>, Error> where
    T: AsRef<str>, 
[src]

Will prepare statement. See Conn::prepare.

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

pub fn prep_exec<A, T>(
    &self,
    query: A,
    params: T
) -> Result<QueryResult<'static>, Error> where
    A: AsRef<str>,
    T: Into<Params>, 
[src]

Shortcut for pool.get_conn()?.prep_exec(..). See Conn::prep_exec.

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

pub fn first_exec<Q, P>(
    &self,
    query: Q,
    params: P
) -> Result<Option<Row>, Error> where
    P: Into<Params>,
    Q: AsRef<str>, 
[src]

pub fn start_transaction(
    &self,
    consistent_snapshot: bool,
    isolation_level: Option<IsolationLevel>,
    readonly: Option<bool>
) -> Result<Transaction<'static>, Error>
[src]

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

Trait Implementations

impl Clone for Pool[src]

impl Debug for Pool[src]

Auto Trait Implementations

impl Send for Pool

impl Sync for Pool

impl Unpin for Pool

impl !UnwindSafe for Pool

impl !RefUnwindSafe for Pool

Blanket Implementations

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

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

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<T> Borrow<T> for T where
    T: ?Sized
[src]

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

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

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

impl<T> Same<T> for T

type Output = T

Should always be Self