Struct Conn

Source
pub struct Conn { /* private fields */ }
Expand description

MySql server connection.

Implementations§

Source§

impl Conn

Source

pub fn id(&self) -> u32

Returns connection identifier.

Source

pub fn last_insert_id(&self) -> Option<u64>

Returns the ID generated by a query (usually INSERT) on a table with a column having the AUTO_INCREMENT attribute. Returns None if there was no previous query on the connection or if the query did not update an AUTO_INCREMENT value.

Source

pub fn affected_rows(&self) -> u64

Returns the number of rows affected by the last INSERT, UPDATE, REPLACE or DELETE query.

Source

pub fn info(&self) -> Cow<'_, str>

Text information, as reported by the server in the last OK packet, or an empty string.

Source

pub fn get_warnings(&self) -> u16

Number of warnings, as reported by the server in the last OK packet, or 0.

Source

pub fn last_ok_packet(&self) -> Option<&OkPacket<'static>>

Returns a reference to the last OK packet.

Source

pub fn reset_connection(&mut self, reset_connection: bool)

Turns on/off automatic connection reset (see crate::PoolOpts::with_reset_connection).

Only makes sense for pooled connections.

Source

pub fn server_version(&self) -> (u16, u16, u16)

Returns server version.

Source

pub fn opts(&self) -> &Opts

Returns connection options.

Source

pub fn set_infile_handler<T>(&mut self, handler: T)
where T: Future<Output = Result<InfileData>> + Send + Sync + 'static,

Setup local LOCAL INFILE handler (see “LOCAL INFILE Handlers” section of the crate-level docs).

It’ll overwrite existing local handler, if any.

Source

pub async fn disconnect(self) -> Result<()>

Disconnects this connection from server.

Source

pub fn new<T: Into<Opts>>(opts: T) -> BoxFuture<'static, Result<Conn>>

Returns a future that resolves to Conn.

Source

pub async fn from_url<T: AsRef<str>>(url: T) -> Result<Conn>

Returns a future that resolves to Conn.

Source

pub async fn reset(&mut self) -> Result<bool>

Executes COM_RESET_CONNECTION.

Returns false if command is not supported (requires MySql >5.7.2, MariaDb >10.2.3). For older versions consider using Conn::change_user.

Source

pub async fn change_user(&mut self, opts: ChangeUserOpts) -> Result<()>

Executes COM_CHANGE_USER.

This might be used as an older and slower alternative to COM_RESET_CONNECTION that works on MySql prior to 5.7.3 (MariaDb prior ot 10.2.4).

§Note
  • Using non-default opts for a pooled connection is discouraging.
  • Connection options will be permanently updated.
Source§

impl Conn

Source

pub async fn start_transaction( &mut self, options: TxOpts, ) -> Result<Transaction<'_>>

Starts a transaction.

Trait Implementations§

Source§

impl Debug for Conn

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Conn

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a> From<&'a mut Conn> for Connection<'a, 'static>

Source§

fn from(conn: &'a mut Conn) -> Self

Converts to this type from the input type.
Source§

impl From<Conn> for Connection<'static, 'static>

Source§

fn from(conn: Conn) -> Self

Converts to this type from the input type.
Source§

impl Queryable for Conn

Source§

fn ping(&mut self) -> BoxFuture<'_, Result<()>>

Executes COM_PING.
Source§

fn query_iter<'a, Q>( &'a mut self, query: Q, ) -> BoxFuture<'a, Result<QueryResult<'a, 'static, TextProtocol>>>
where Q: AsQuery + 'a,

Performs the given query and returns the result.
Source§

fn prep<'a, Q>(&'a mut self, query: Q) -> BoxFuture<'a, Result<Statement>>
where Q: AsQuery + 'a,

Prepares the given statement. Read more
Source§

fn close(&mut self, stmt: Statement) -> BoxFuture<'_, Result<()>>

Closes the given statement. Read more
Source§

fn exec_iter<'a: 's, 's, Q, P>( &'a mut self, stmt: Q, params: P, ) -> BoxFuture<'s, Result<QueryResult<'a, 'static, BinaryProtocol>>>
where Q: StatementLike + 'a, P: Into<Params>,

Executes the given statement with given params. Read more
Source§

fn exec_batch<'a: 'b, 'b, S, P, I>( &'a mut self, stmt: S, params_iter: I, ) -> BoxFuture<'b, Result<()>>
where S: StatementLike + 'b, I: IntoIterator<Item = P> + Send + 'b, I::IntoIter: Send, P: Into<Params> + Send,

Executes the given statement for each item in the given params iterator. Read more
Source§

fn query<'a, T, Q>(&'a mut self, query: Q) -> BoxFuture<'a, Result<Vec<T>>>
where Q: AsQuery + 'a, T: FromRow + Send + 'static,

Performs the given query and collects the first result set. Read more
Source§

fn query_first<'a, T, Q>( &'a mut self, query: Q, ) -> BoxFuture<'a, Result<Option<T>>>
where Q: AsQuery + 'a, T: FromRow + Send + 'static,

Performs the given query and returns the first row of the first result set. Read more
Source§

fn query_map<'a, T, F, Q, U>( &'a mut self, query: Q, f: F, ) -> BoxFuture<'a, Result<Vec<U>>>
where Q: AsQuery + 'a, T: FromRow + Send + 'static, F: FnMut(T) -> U + Send + 'a, U: Send,

Performs the given query and maps each row of the first result set. Read more
Source§

fn query_fold<'a, T, F, Q, U>( &'a mut self, query: Q, init: U, f: F, ) -> BoxFuture<'a, Result<U>>
where Q: AsQuery + 'a, T: FromRow + Send + 'static, F: FnMut(U, T) -> U + Send + 'a, U: Send + 'a,

Performs the given query and folds the first result set to a single value. Read more
Source§

fn query_drop<'a, Q>(&'a mut self, query: Q) -> BoxFuture<'a, Result<()>>
where Q: AsQuery + 'a,

Performs the given query and drops the query result.
Source§

fn exec<'a: 'b, 'b, T, S, P>( &'a mut self, stmt: S, params: P, ) -> BoxFuture<'b, Result<Vec<T>>>
where S: StatementLike + 'b, P: Into<Params> + Send + 'b, T: FromRow + Send + 'static,

Executes the given statement and collects the first result set. Read more
Source§

fn exec_first<'a: 'b, 'b, T, S, P>( &'a mut self, stmt: S, params: P, ) -> BoxFuture<'b, Result<Option<T>>>
where S: StatementLike + 'b, P: Into<Params> + Send + 'b, T: FromRow + Send + 'static,

Executes the given statement and returns the first row of the first result set. Read more
Source§

fn exec_map<'a: 'b, 'b, T, S, P, U, F>( &'a mut self, stmt: S, params: P, f: F, ) -> BoxFuture<'b, Result<Vec<U>>>
where S: StatementLike + 'b, P: Into<Params> + Send + 'b, T: FromRow + Send + 'static, F: FnMut(T) -> U + Send + 'a, U: Send + 'a,

Executes the given stmt and maps each row of the first result set. Read more
Source§

fn exec_fold<'a: 'b, 'b, T, S, P, U, F>( &'a mut self, stmt: S, params: P, init: U, f: F, ) -> BoxFuture<'b, Result<U>>
where S: StatementLike + 'b, P: Into<Params> + Send + 'b, T: FromRow + Send + 'static, F: FnMut(U, T) -> U + Send + 'a, U: Send + 'a,

Executes the given stmt and folds the first result set to a signel value. Read more
Source§

fn exec_drop<'a: 'b, 'b, S, P>( &'a mut self, stmt: S, params: P, ) -> BoxFuture<'b, Result<()>>
where S: StatementLike + 'b, P: Into<Params> + Send + 'b,

Executes the given statement and drops the result.
Source§

fn query_stream<'a, T, Q>( &'a mut self, query: Q, ) -> BoxFuture<'a, Result<ResultSetStream<'a, 'a, 'static, T, TextProtocol>>>
where T: Unpin + FromRow + Send + 'static, Q: AsQuery + 'a,

Returns a stream over the first result set. Read more
Source§

fn exec_stream<'a: 's, 's, T, Q, P>( &'a mut self, stmt: Q, params: P, ) -> BoxFuture<'s, Result<ResultSetStream<'a, 'a, 'static, T, BinaryProtocol>>>
where T: Unpin + FromRow + Send + 'static, Q: StatementLike + 'a, P: Into<Params> + Send + 's,

Returns a stream over the first result set. Read more

Auto Trait Implementations§

§

impl Freeze for Conn

§

impl !RefUnwindSafe for Conn

§

impl Send for Conn

§

impl Sync for Conn

§

impl Unpin for Conn

§

impl !UnwindSafe for Conn

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<'a, 't, T> ToConnection<'a, 't> for T
where 't: 'a, T: Into<Connection<'a, 't>> + Send,

Source§

fn to_connection(self) -> ToConnectionResult<'a, 't>

Converts self to a connection.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T