pub struct PooledConn { /* private fields */ }Expand description
Pooled mysql connection.
You should prefer using prep along exec instead of query from the Queryable trait where
possible, except cases when statement has no params and when it has no return values or return
values which evaluates to Value::Bytes.
query is a part of mysql text protocol, so under the hood you will always receive
Value::Bytes as a result and from_value will need to parse it if you want, for example, i64
let pool = Pool::new(get_opts()).unwrap();
let mut conn = pool.get_conn().unwrap();
conn.query_first("SELECT 42").map(|result: Option<Value>| {
let result = result.unwrap();
assert_eq!(result, Value::Bytes(b"42".to_vec()));
assert_eq!(from_value::<i64>(result), 42i64);
}).unwrap();
conn.exec_iter("SELECT 42", ()).map(|mut result| {
let cell = result.next().unwrap().unwrap().take(0).unwrap();
assert_eq!(cell, Value::Int(42i64));
assert_eq!(from_value::<i64>(cell), 42i64);
}).unwrap();For more info on how to work with query results please look at
QueryResult documentation.
Implementations§
Source§impl PooledConn
impl PooledConn
Sourcepub fn start_transaction(&mut self, tx_opts: TxOpts) -> Result<Transaction<'_>>
pub fn start_transaction(&mut self, tx_opts: TxOpts) -> Result<Transaction<'_>>
Redirects to
Conn#start_transaction
Sourcepub fn set_local_infile_handler(&mut self, handler: Option<LocalInfileHandler>)
pub fn set_local_infile_handler(&mut self, handler: Option<LocalInfileHandler>)
A way to override default local infile handler for this pooled connection. Destructor will
restore original handler before returning connection to a pool.
See Conn::set_local_infile_handler.
Sourcepub fn change_user(&mut self) -> Result<()>
pub fn change_user(&mut self) -> Result<()>
Invokes COM_CHANGE_USER (see Conn::change_user docs).
Sourcepub fn reset_connection(&mut self, reset_connection: bool)
pub fn reset_connection(&mut self, reset_connection: bool)
Turns on/off automatic connection reset upon return to a pool (see Opts::get_pool_opts).
Initial value is taken from crate::PoolOpts::reset_connection.
Methods from Deref<Target = Conn>§
Sourcepub fn server_version(&self) -> (u16, u16, u16)
pub fn server_version(&self) -> (u16, u16, u16)
Returns version number reported by the server.
Sourcepub fn connection_id(&self) -> u32
pub fn connection_id(&self) -> u32
Returns connection identifier.
Sourcepub fn affected_rows(&self) -> u64
pub fn affected_rows(&self) -> u64
Returns number of rows affected by the last query.
Sourcepub fn last_insert_id(&self) -> u64
pub fn last_insert_id(&self) -> u64
Returns last insert id of the last query.
Returns zero if there was no last insert id.
Sourcepub fn info_str(&self) -> Cow<'_, str>
pub fn info_str(&self) -> Cow<'_, str>
Info, reported by the server.
Will be empty if not defined.
pub fn session_state_changes(&self) -> Result<Vec<SessionStateInfo<'_>>>
pub fn no_backslash_escape(&self) -> bool
Trait Implementations§
Source§impl AsMut<Conn> for PooledConn
impl AsMut<Conn> for PooledConn
Source§impl AsRef<Conn> for PooledConn
impl AsRef<Conn> for PooledConn
Source§impl Debug for PooledConn
impl Debug for PooledConn
Source§impl Deref for PooledConn
impl Deref for PooledConn
Source§impl Drop for PooledConn
impl Drop for PooledConn
Source§impl Queryable for PooledConn
impl Queryable for PooledConn
Source§fn query_iter<T: AsRef<str>>(
&mut self,
query: T,
) -> Result<QueryResult<'_, '_, '_, Text>>
fn query_iter<T: AsRef<str>>( &mut self, query: T, ) -> Result<QueryResult<'_, '_, '_, Text>>
Source§fn prep<T: AsRef<str>>(&mut self, query: T) -> Result<Statement>
fn prep<T: AsRef<str>>(&mut self, query: T) -> Result<Statement>
query as a prepared statement.Source§fn close(&mut self, stmt: Statement) -> Result<()>
fn close(&mut self, stmt: Statement) -> Result<()>
Source§fn exec_iter<S, P>(
&mut self,
stmt: S,
params: P,
) -> Result<QueryResult<'_, '_, '_, Binary>>
fn exec_iter<S, P>( &mut self, stmt: S, params: P, ) -> Result<QueryResult<'_, '_, '_, Binary>>
stmt with the given params.Source§fn query<T, Q>(&mut self, query: Q) -> Result<Vec<T>>
fn query<T, Q>(&mut self, query: Q) -> Result<Vec<T>>
Source§fn query_opt<T, Q>(
&mut self,
query: Q,
) -> Result<Vec<StdResult<T, FromRowError>>>
fn query_opt<T, Q>( &mut self, query: Q, ) -> Result<Vec<StdResult<T, FromRowError>>>
Queryable::query but useful when you not sure what your schema is.Source§fn query_first<T, Q>(&mut self, query: Q) -> Result<Option<T>>
fn query_first<T, Q>(&mut self, query: Q) -> Result<Option<T>>
Source§fn query_first_opt<T, Q>(
&mut self,
query: Q,
) -> Result<Option<StdResult<T, FromRowError>>>
fn query_first_opt<T, Q>( &mut self, query: Q, ) -> Result<Option<StdResult<T, FromRowError>>>
Queryable::query_first but useful when you not sure what your schema is.Source§fn query_map<T, F, Q, U>(&mut self, query: Q, f: F) -> Result<Vec<U>>
fn query_map<T, F, Q, U>(&mut self, query: Q, f: F) -> Result<Vec<U>>
Source§fn query_map_opt<T, F, Q, U>(&mut self, query: Q, f: F) -> Result<Vec<U>>
fn query_map_opt<T, F, Q, U>(&mut self, query: Q, f: F) -> Result<Vec<U>>
Queryable::query_map but useful when you not sure what your schema is.Source§fn query_fold<T, F, Q, U>(&mut self, query: Q, init: U, f: F) -> Result<U>
fn query_fold<T, F, Q, U>(&mut self, query: Q, init: U, f: F) -> Result<U>
Source§fn query_fold_opt<T, F, Q, U>(&mut self, query: Q, init: U, f: F) -> Result<U>
fn query_fold_opt<T, F, Q, U>(&mut self, query: Q, init: U, f: F) -> Result<U>
Queryable::query_fold but useful when you not sure what your schema is.Source§fn query_drop<Q>(&mut self, query: Q) -> Result<()>
fn query_drop<Q>(&mut self, query: Q) -> Result<()>
Source§fn exec_batch<S, P, I>(&mut self, stmt: S, params: I) -> Result<()>
fn exec_batch<S, P, I>(&mut self, stmt: S, params: I) -> Result<()>
Source§fn exec<T, S, P>(&mut self, stmt: S, params: P) -> Result<Vec<T>>
fn exec<T, S, P>(&mut self, stmt: S, params: P) -> Result<Vec<T>>
stmt and collects the first result set.Source§fn exec_opt<T, S, P>(
&mut self,
stmt: S,
params: P,
) -> Result<Vec<StdResult<T, FromRowError>>>
fn exec_opt<T, S, P>( &mut self, stmt: S, params: P, ) -> Result<Vec<StdResult<T, FromRowError>>>
Queryable::exec but useful when you not sure what your schema is.Source§fn exec_first<T, S, P>(&mut self, stmt: S, params: P) -> Result<Option<T>>
fn exec_first<T, S, P>(&mut self, stmt: S, params: P) -> Result<Option<T>>
stmt and returns the first row of the first result set.Source§fn exec_first_opt<T, S, P>(
&mut self,
stmt: S,
params: P,
) -> Result<Option<StdResult<T, FromRowError>>>
fn exec_first_opt<T, S, P>( &mut self, stmt: S, params: P, ) -> Result<Option<StdResult<T, FromRowError>>>
Queryable::exec_first but useful when you not sure what your schema is.Source§fn exec_map<T, S, P, F, U>(
&mut self,
stmt: S,
params: P,
f: F,
) -> Result<Vec<U>>
fn exec_map<T, S, P, F, U>( &mut self, stmt: S, params: P, f: F, ) -> Result<Vec<U>>
stmt and maps each row of the first result set.Source§fn exec_map_opt<T, S, P, F, U>(
&mut self,
stmt: S,
params: P,
f: F,
) -> Result<Vec<U>>
fn exec_map_opt<T, S, P, F, U>( &mut self, stmt: S, params: P, f: F, ) -> Result<Vec<U>>
Queryable::exec_map but useful when you not sure what your schema is.Source§fn exec_fold<T, S, P, U, F>(
&mut self,
stmt: S,
params: P,
init: U,
f: F,
) -> Result<U>
fn exec_fold<T, S, P, U, F>( &mut self, stmt: S, params: P, init: U, f: F, ) -> Result<U>
stmt and folds the first result set to a single value.Source§fn exec_fold_opt<T, S, P, U, F>(
&mut self,
stmt: S,
params: P,
init: U,
f: F,
) -> Result<U>
fn exec_fold_opt<T, S, P, U, F>( &mut self, stmt: S, params: P, init: U, f: F, ) -> Result<U>
Queryable::exec_fold but useful when you not sure what your schema is.