Struct mysql::PooledConn
source · pub struct PooledConn { /* private fields */ }
Expand description
Pooled mysql connection which will return to the pool on drop
.
You should prefer using prepare
or prep_exec
instead of query
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 mut conn = pool.get_conn().unwrap();
conn.query("SELECT 42").map(|mut result| {
let cell = result.next().unwrap().unwrap().take(0).unwrap();
assert_eq!(cell, Value::Bytes(b"42".to_vec()));
assert_eq!(from_value::<i64>(cell), 42i64);
}).unwrap();
conn.prep_exec("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 query<T: AsRef<str>>(&mut self, query: T) -> MyResult<QueryResult<'_>>
pub fn query<T: AsRef<str>>(&mut self, query: T) -> MyResult<QueryResult<'_>>
Redirects to
Conn#query
.
sourcepub fn first<T: AsRef<str>, U: FromRow>(
&mut self,
query: T
) -> MyResult<Option<U>>
pub fn first<T: AsRef<str>, U: FromRow>(
&mut self,
query: T
) -> MyResult<Option<U>>
See Conn::first
.
sourcepub fn prep_exec<A, T>(
&mut self,
query: A,
params: T
) -> MyResult<QueryResult<'_>>where
A: AsRef<str>,
T: Into<Params>,
pub fn prep_exec<A, T>(
&mut self,
query: A,
params: T
) -> MyResult<QueryResult<'_>>where
A: AsRef<str>,
T: Into<Params>,
See Conn::prep_exec
.
sourcepub fn first_exec<Q, P, T>(&mut self, query: Q, params: P) -> MyResult<Option<T>>where
Q: AsRef<str>,
P: Into<Params>,
T: FromRow,
pub fn first_exec<Q, P, T>(&mut self, query: Q, params: P) -> MyResult<Option<T>>where
Q: AsRef<str>,
P: Into<Params>,
T: FromRow,
See Conn::first_exec
.
sourcepub fn start_transaction<'a>(
&'a mut self,
consistent_snapshot: bool,
isolation_level: Option<IsolationLevel>,
readonly: Option<bool>
) -> MyResult<Transaction<'a>>
pub fn start_transaction<'a>(
&'a mut self,
consistent_snapshot: bool,
isolation_level: Option<IsolationLevel>,
readonly: Option<bool>
) -> MyResult<Transaction<'a>>
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
.
Trait Implementations§
source§impl Debug for PooledConn
impl Debug for PooledConn
source§impl Drop for PooledConn
impl Drop for PooledConn
source§impl GenericConnection for PooledConn
impl GenericConnection for PooledConn
source§fn query<T: AsRef<str>>(&mut self, query: T) -> MyResult<QueryResult<'_>>
fn query<T: AsRef<str>>(&mut self, query: T) -> MyResult<QueryResult<'_>>
Conn#query
. Read moresource§fn first<T: AsRef<str>, U: FromRow>(&mut self, query: T) -> MyResult<Option<U>>
fn first<T: AsRef<str>, U: FromRow>(&mut self, query: T) -> MyResult<Option<U>>
Conn#first
. Read moresource§fn prepare<T: AsRef<str>>(&mut self, query: T) -> MyResult<Stmt<'_>>
fn prepare<T: AsRef<str>>(&mut self, query: T) -> MyResult<Stmt<'_>>
Conn#prepare
. Read more