Skip to main content

Transaction

Struct Transaction 

Source
pub struct Transaction<'a> { /* private fields */ }
Expand description

An instrumented transaction, from Client::transaction. Like tokio-postgres’s, dropping it without committing rolls it back, but that rollback isn’t recorded. It dereferences to tokio-postgres’s Transaction.

Implementations§

Source§

impl<'a> Transaction<'a>

Source

pub async fn prepare(&self, query: &str) -> Result<Statement, Error>

Prepare a statement, keeping its text so that calls running it are named. Preparing isn’t recorded as a call.

Source

pub async fn query<T>( &self, statement: &T, params: &[&(dyn ToSql + Sync)], ) -> Result<Vec<Row>, Error>
where T: ?Sized + Query,

Run a statement and return the rows it produced.

Source

pub async fn query_one<T>( &self, statement: &T, params: &[&(dyn ToSql + Sync)], ) -> Result<Row, Error>
where T: ?Sized + Query,

Run a statement that returns exactly one row.

Source

pub async fn query_opt<T>( &self, statement: &T, params: &[&(dyn ToSql + Sync)], ) -> Result<Option<Row>, Error>
where T: ?Sized + Query,

Run a statement that returns at most one row.

Source

pub async fn execute<T>( &self, statement: &T, params: &[&(dyn ToSql + Sync)], ) -> Result<u64, Error>
where T: ?Sized + Query,

Run a statement and return how many rows it changed.

Source

pub async fn batch_execute(&self, query: &str) -> Result<(), Error>

Run statements separated by semicolons, without parameters, as one call.

Source

pub async fn simple_query( &self, query: &str, ) -> Result<Vec<SimpleQueryMessage>, Error>

Run statements through the simple query protocol, as one call.

Source

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

Commit, recorded as a call.

Source

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

Roll back, recorded as a call.

Source

pub async fn transaction(&mut self) -> Result<Transaction<'_>, Error>

Start a nested transaction, which is a savepoint, recorded as a call.

Methods from Deref<Target = Transaction<'a>>§

Source

pub async fn prepare(&self, query: &str) -> Result<Statement, Error>

Like Client::prepare.

Source

pub async fn prepare_typed( &self, query: &str, parameter_types: &[Type], ) -> Result<Statement, Error>

Like Client::prepare_typed.

Source

pub async fn query<T>( &self, statement: &T, params: &[&(dyn ToSql + Sync)], ) -> Result<Vec<Row>, Error>
where T: ToStatement + ?Sized,

Like Client::query.

Source

pub async fn query_one<T>( &self, statement: &T, params: &[&(dyn ToSql + Sync)], ) -> Result<Row, Error>
where T: ToStatement + ?Sized,

Like Client::query_one.

Source

pub async fn query_opt<T>( &self, statement: &T, params: &[&(dyn ToSql + Sync)], ) -> Result<Option<Row>, Error>
where T: ToStatement + ?Sized,

Like Client::query_opt.

Source

pub async fn query_raw<T, P, I>( &self, statement: &T, params: I, ) -> Result<RowStream, Error>

Like Client::query_raw.

Source

pub async fn query_typed( &self, statement: &str, params: &[(&(dyn ToSql + Sync), Type)], ) -> Result<Vec<Row>, Error>

Like Client::query_typed.

Source

pub async fn query_typed_one( &self, statement: &str, params: &[(&(dyn ToSql + Sync), Type)], ) -> Result<Row, Error>

Like Client::query_typed_one.

Source

pub async fn query_typed_opt( &self, statement: &str, params: &[(&(dyn ToSql + Sync), Type)], ) -> Result<Option<Row>, Error>

Like Client::query_typed_opt.

Source

pub async fn query_typed_raw<P, I>( &self, query: &str, params: I, ) -> Result<RowStream, Error>
where P: BorrowToSql, I: IntoIterator<Item = (P, Type)>,

Like Client::query_typed_raw.

Source

pub async fn execute<T>( &self, statement: &T, params: &[&(dyn ToSql + Sync)], ) -> Result<u64, Error>
where T: ToStatement + ?Sized,

Like Client::execute.

Source

pub async fn execute_typed( &self, statement: &str, params: &[(&(dyn ToSql + Sync), Type)], ) -> Result<u64, Error>

Like Client::execute_typed.

Source

pub async fn execute_raw<P, I, T>( &self, statement: &T, params: I, ) -> Result<u64, Error>

Like Client::execute_iter.

Source

pub async fn bind<T>( &self, statement: &T, params: &[&(dyn ToSql + Sync)], ) -> Result<Portal, Error>
where T: ToStatement + ?Sized,

Binds a statement to a set of parameters, creating a Portal which can be incrementally queried.

Portals only last for the duration of the transaction in which they are created, and can only be used on the connection that created them.

§Panics

Panics if the number of parameters provided does not match the number expected.

Source

pub async fn bind_raw<P, T, I>( &self, statement: &T, params: I, ) -> Result<Portal, Error>

A maximally flexible version of bind.

Source

pub async fn query_portal( &self, portal: &Portal, max_rows: i32, ) -> Result<Vec<Row>, Error>

Continues execution of a portal, returning a stream of the resulting rows.

Unlike query, portals can be incrementally evaluated by limiting the number of rows returned in each call to query_portal. If the requested number is negative or 0, all rows will be returned.

Source

pub async fn query_portal_raw( &self, portal: &Portal, max_rows: i32, ) -> Result<RowStream, Error>

The maximally flexible version of query_portal.

Source

pub async fn copy_in<T, U>(&self, statement: &T) -> Result<CopyInSink<U>, Error>
where T: ToStatement + ?Sized, U: Buf + 'static + Send,

Like Client::copy_in.

Source

pub async fn copy_out<T>(&self, statement: &T) -> Result<CopyOutStream, Error>
where T: ToStatement + ?Sized,

Like Client::copy_out.

Source

pub async fn simple_query( &self, query: &str, ) -> Result<Vec<SimpleQueryMessage>, Error>

Like Client::simple_query.

Source

pub async fn batch_execute(&self, query: &str) -> Result<(), Error>

Like Client::batch_execute.

Source

pub fn cancel_token(&self) -> CancelToken

Like Client::cancel_token.

Source

pub async fn cancel_query<T>(&self, tls: T) -> Result<(), Error>

👎Deprecated since 0.6.0:

use Transaction::cancel_token() instead

Like Client::cancel_query.

Source

pub async fn cancel_query_raw<S, T>( &self, stream: S, tls: T, ) -> Result<(), Error>
where S: AsyncRead + AsyncWrite + Unpin, T: TlsConnect<S>,

👎Deprecated since 0.6.0:

use Transaction::cancel_token() instead

Like Client::cancel_query_raw.

Source

pub fn client(&self) -> &Client

Returns a reference to the underlying Client.

Trait Implementations§

Source§

impl Debug for Transaction<'_>

Source§

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

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

impl<'a> Deref for Transaction<'a>

Source§

type Target = Transaction<'a>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Transaction<'a>

Dereferences the value.
Source§

impl GenericClient for Transaction<'_>

Source§

fn prepare( &self, query: &str, ) -> impl Future<Output = Result<Statement, Error>> + Send

Source§

fn query<T>( &self, statement: &T, params: &[&(dyn ToSql + Sync)], ) -> impl Future<Output = Result<Vec<Row>, Error>> + Send
where T: ?Sized + Query,

Source§

fn query_one<T>( &self, statement: &T, params: &[&(dyn ToSql + Sync)], ) -> impl Future<Output = Result<Row, Error>> + Send
where T: ?Sized + Query,

Source§

fn query_opt<T>( &self, statement: &T, params: &[&(dyn ToSql + Sync)], ) -> impl Future<Output = Result<Option<Row>, Error>> + Send
where T: ?Sized + Query,

Source§

fn execute<T>( &self, statement: &T, params: &[&(dyn ToSql + Sync)], ) -> impl Future<Output = Result<u64, Error>> + Send
where T: ?Sized + Query,

Source§

fn batch_execute( &self, query: &str, ) -> impl Future<Output = Result<(), Error>> + Send

Auto Trait Implementations§

§

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

§

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

§

impl<'a> Freeze for Transaction<'a>

§

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

§

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

§

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

§

impl<'a> UnsafeUnpin 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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 = !

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

fn try_from(value: U) -> Result<T, !>

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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more