Struct Transaction

Source
pub struct Transaction<'a>(/* private fields */);
Expand description

This struct represents MySql transaction.

Transaction is just a sugar for START TRANSACTION, ROLLBACK and COMMIT queries, so please note, that it is easy to mess things up calling this queries manually.

You should always call either commit or rollback, otherwise transaction will be rolled back implicitly when corresponding connection is dropped or queried.

Implementations§

Source§

impl<'a> Transaction<'a>

Source

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

Performs COMMIT query or rollbacks when any error occurs and returns the original error.

Source

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

Performs ROLLBACK query.

Methods from Deref<Target = 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 server_version(&self) -> (u16, u16, u16)

Returns server version.

Source

pub fn opts(&self) -> &Opts

Returns connection options.

Trait Implementations§

Source§

impl<'a> Debug for Transaction<'a>

Source§

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

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

impl Deref for Transaction<'_>

Source§

type Target = Conn

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Drop for Transaction<'_>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, 't> From<&'a mut Transaction<'t>> for Connection<'a, 't>

Source§

fn from(tx: &'a mut Transaction<'t>) -> Self

Converts to this type from the input type.
Source§

impl Queryable for Transaction<'_>

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<'a> Freeze for Transaction<'a>

§

impl<'a> !RefUnwindSafe for Transaction<'a>

§

impl<'a> Send for Transaction<'a>

§

impl<'a> Sync for Transaction<'a>

§

impl<'a> Unpin for Transaction<'a>

§

impl<'a> !UnwindSafe for Transaction<'a>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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