[−][src]Struct mysql::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:
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(std::thread::spawn(move || { let mut conn = pool.get_conn().unwrap(); let result: u8 = conn.query_first("SELECT 1").unwrap().unwrap(); assert_eq!(result, 1_u8); })); } 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.
Implementations
impl Pool
[src]
pub fn new<T: Into<Opts>>(opts: T) -> Result<Pool>
[src]
Creates new pool with min = 10
and max = 100
.
pub fn new_manual<T: Into<Opts>>(
min: usize,
max: usize,
opts: T
) -> Result<Pool>
[src]
min: usize,
max: usize,
opts: T
) -> Result<Pool>
Same as new
but you can set min
and max
.
pub fn check_health(&mut self, check_health: bool)
[src]
A way to turn off connection health check on each call to get_conn
(on by default).
pub fn get_conn(&self) -> Result<PooledConn>
[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>
[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 start_transaction(&self, tx_opts: TxOpts) -> Result<Transaction<'static>>
[src]
Shortcut for pool.get_conn()?.start_transaction(..)
.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Pool
impl Send for Pool
impl Sync for Pool
impl Unpin for Pool
impl !UnwindSafe for Pool
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub 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.
pub 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.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,