[−][src]Struct c3p0_mysql::mysql::driver::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 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]
T: Into<Opts>,
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]
T: Into<Opts>,
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]
T: AsRef<str>,
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]
&self,
query: A,
params: T
) -> Result<QueryResult<'static>, Error> where
A: AsRef<str>,
T: Into<Params>,
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]
&self,
query: Q,
params: P
) -> Result<Option<Row>, Error> where
P: Into<Params>,
Q: AsRef<str>,
See Conn::first_exec
.
pub fn start_transaction(
&self,
consistent_snapshot: bool,
isolation_level: Option<IsolationLevel>,
readonly: Option<bool>
) -> Result<Transaction<'static>, Error>
[src]
&self,
consistent_snapshot: bool,
isolation_level: Option<IsolationLevel>,
readonly: Option<bool>
) -> Result<Transaction<'static>, Error>
Shortcut for pool.get_conn()?.start_transaction(..)
.
Trait Implementations
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]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
fn vzip(self) -> V
impl<T> Same<T> for T
type Output = T
Should always be Self