Struct postgres::Transaction

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

A representation of a PostgreSQL database transaction.

Transactions will implicitly roll back by default when dropped. Use the commit method to commit the changes made in the transaction. Transactions can be nested, with inner transactions implemented via savepoints.

Implementations§

source§

impl<'a> Transaction<'a>

source

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

Consumes the transaction, committing all changes made within it.

source

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

Rolls the transaction back, discarding all changes made within it.

This is equivalent to Transaction’s Drop implementation, but provides any error encountered to the caller.

source

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

Like Client::prepare.

source

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

Like Client::prepare_typed.

source

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

Like Client::execute.

source

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

Like Client::query.

source

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

Like Client::query_one.

source

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

Like Client::query_opt.

source

pub fn query_raw<T, P, I>( &mut self, query: &T, params: I, ) -> Result<RowIter<'_>, Error>

Like Client::query_raw.

source

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

Like Client::query_typed.

source

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

Like Client::query_typed_raw.

source

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

Binds parameters to a statement, creating a “portal”.

Portals can be used with the query_portal method to page through the results of a query without being forced to consume them all immediately.

Portals are automatically closed when the transaction they were created in is closed.

§Panics

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

source

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

Continues execution of a portal, returning the next set of 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 remaining rows will be returned.

source

pub fn query_portal_raw( &mut self, portal: &Portal, max_rows: i32, ) -> Result<RowIter<'_>, Error>

The maximally flexible version of query_portal.

source

pub fn copy_in<T>(&mut self, query: &T) -> Result<CopyInWriter<'_>, Error>
where T: ?Sized + ToStatement,

Like Client::copy_in.

source

pub fn copy_out<T>(&mut self, query: &T) -> Result<CopyOutReader<'_>, Error>
where T: ?Sized + ToStatement,

Like Client::copy_out.

source

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

Like Client::simple_query.

source

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

Like Client::batch_execute.

source

pub fn cancel_token(&self) -> CancelToken

Like Client::cancel_token.

source

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

Like Client::transaction, but creates a nested transaction via a savepoint.

source

pub fn savepoint<I>(&mut self, name: I) -> Result<Transaction<'_>, Error>
where I: Into<String>,

Like Client::transaction, but creates a nested transaction via a savepoint with the specified name.

Trait Implementations§

source§

impl<'a> Drop for Transaction<'a>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl GenericClient for Transaction<'_>

source§

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

Like Client::execute.
source§

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

Like Client::query.
source§

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

Like Client::query_one.
source§

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

Like Client::query_opt.
source§

fn query_raw<T, P, I>( &mut self, query: &T, params: I, ) -> Result<RowIter<'_>, Error>

Like Client::query_raw.
source§

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

source§

fn query_typed_raw<P, I>( &mut self, statement: &str, params: I, ) -> Result<RowIter<'_>, Error>
where P: BorrowToSql, I: IntoIterator<Item = (P, Type)> + Sync + Send,

source§

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

Like Client::prepare.
source§

fn prepare_typed( &mut self, query: &str, types: &[Type], ) -> Result<Statement, Error>

Like Client::prepare_typed.
source§

fn copy_in<T>(&mut self, query: &T) -> Result<CopyInWriter<'_>, Error>
where T: ?Sized + ToStatement,

Like Client::copy_in.
source§

fn copy_out<T>(&mut self, query: &T) -> Result<CopyOutReader<'_>, Error>
where T: ?Sized + ToStatement,

Like Client::copy_out.
source§

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

Like Client::simple_query.
source§

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

Like Client::batch_execute.
source§

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

Like Client::transaction.

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

§

type Output = T

Should always be Self
source§

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

§

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>,

§

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> 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