pub struct Pool { /* private fields */ }
Expand description
Thread-safe cloneable smart pointer to a connection pool.
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 pool = Pool::new(opts).unwrap();
let mut threads = Vec::new();
for _ in 0..1000 {
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§
Source§impl Pool
impl Pool
Sourcepub fn get_conn(&self) -> Result<PooledConn>
pub fn get_conn(&self) -> Result<PooledConn>
Gives you a PooledConn
.
Sourcepub fn try_get_conn(&self, timeout: Duration) -> Result<PooledConn>
pub fn try_get_conn(&self, timeout: Duration) -> Result<PooledConn>
Will try to get connection for the duration of timeout
.
§Failure
This function will return Error::DriverError(DriverError::Timeout)
if timeout was
reached while waiting for new connection to become available.
Sourcepub fn start_transaction(&self, tx_opts: TxOpts) -> Result<Transaction<'static>>
pub fn start_transaction(&self, tx_opts: TxOpts) -> Result<Transaction<'static>>
Shortcut for pool.get_conn()?.start_transaction(..)
.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Pool
impl RefUnwindSafe for Pool
impl Send for Pool
impl Sync for Pool
impl Unpin for Pool
impl UnwindSafe for Pool
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more