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>
impl<'a> Transaction<'a>
sourcepub fn commit(self) -> Result<(), Error>
pub fn commit(self) -> Result<(), Error>
Consumes the transaction, committing all changes made within it.
sourcepub fn rollback(self) -> Result<(), Error>
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.
sourcepub fn prepare_typed(
&mut self,
query: &str,
types: &[Type],
) -> Result<Statement, Error>
pub fn prepare_typed( &mut self, query: &str, types: &[Type], ) -> Result<Statement, Error>
Like Client::prepare_typed
.
sourcepub fn execute<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
) -> Result<u64, Error>where
T: ?Sized + ToStatement,
pub fn execute<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
) -> Result<u64, Error>where
T: ?Sized + ToStatement,
Like Client::execute
.
sourcepub fn query<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
) -> Result<Vec<Row>, Error>where
T: ?Sized + ToStatement,
pub fn query<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
) -> Result<Vec<Row>, Error>where
T: ?Sized + ToStatement,
Like Client::query
.
sourcepub fn query_one<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
) -> Result<Row, Error>where
T: ?Sized + ToStatement,
pub fn query_one<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
) -> Result<Row, Error>where
T: ?Sized + ToStatement,
Like Client::query_one
.
sourcepub fn query_opt<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
) -> Result<Option<Row>, Error>where
T: ?Sized + ToStatement,
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
.
sourcepub fn query_raw<T, P, I>(
&mut self,
query: &T,
params: I,
) -> Result<RowIter<'_>, Error>where
T: ?Sized + ToStatement,
P: BorrowToSql,
I: IntoIterator<Item = P>,
I::IntoIter: ExactSizeIterator,
pub fn query_raw<T, P, I>(
&mut self,
query: &T,
params: I,
) -> Result<RowIter<'_>, Error>where
T: ?Sized + ToStatement,
P: BorrowToSql,
I: IntoIterator<Item = P>,
I::IntoIter: ExactSizeIterator,
Like Client::query_raw
.
sourcepub fn query_typed(
&mut self,
statement: &str,
params: &[(&(dyn ToSql + Sync), Type)],
) -> Result<Vec<Row>, Error>
pub fn query_typed( &mut self, statement: &str, params: &[(&(dyn ToSql + Sync), Type)], ) -> Result<Vec<Row>, Error>
Like Client::query_typed
.
sourcepub fn query_typed_raw<P, I>(
&mut self,
query: &str,
params: I,
) -> Result<RowIter<'_>, Error>
pub fn query_typed_raw<P, I>( &mut self, query: &str, params: I, ) -> Result<RowIter<'_>, Error>
Like Client::query_typed_raw
.
sourcepub fn bind<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
) -> Result<Portal, Error>where
T: ?Sized + ToStatement,
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.
sourcepub fn query_portal(
&mut self,
portal: &Portal,
max_rows: i32,
) -> Result<Vec<Row>, Error>
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.
sourcepub fn query_portal_raw(
&mut self,
portal: &Portal,
max_rows: i32,
) -> Result<RowIter<'_>, Error>
pub fn query_portal_raw( &mut self, portal: &Portal, max_rows: i32, ) -> Result<RowIter<'_>, Error>
The maximally flexible version of query_portal
.
sourcepub fn copy_in<T>(&mut self, query: &T) -> Result<CopyInWriter<'_>, Error>where
T: ?Sized + ToStatement,
pub fn copy_in<T>(&mut self, query: &T) -> Result<CopyInWriter<'_>, Error>where
T: ?Sized + ToStatement,
Like Client::copy_in
.
sourcepub fn copy_out<T>(&mut self, query: &T) -> Result<CopyOutReader<'_>, Error>where
T: ?Sized + ToStatement,
pub fn copy_out<T>(&mut self, query: &T) -> Result<CopyOutReader<'_>, Error>where
T: ?Sized + ToStatement,
Like Client::copy_out
.
sourcepub fn simple_query(
&mut self,
query: &str,
) -> Result<Vec<SimpleQueryMessage>, Error>
pub fn simple_query( &mut self, query: &str, ) -> Result<Vec<SimpleQueryMessage>, Error>
Like Client::simple_query
.
sourcepub fn cancel_token(&self) -> CancelToken
pub fn cancel_token(&self) -> CancelToken
Like Client::cancel_token
.
sourcepub fn transaction(&mut self) -> Result<Transaction<'_>, Error>
pub fn transaction(&mut self) -> Result<Transaction<'_>, Error>
Like Client::transaction
, but creates a nested transaction via a savepoint.
Trait Implementations§
source§impl<'a> Drop for Transaction<'a>
impl<'a> Drop for Transaction<'a>
source§impl GenericClient for Transaction<'_>
impl GenericClient for Transaction<'_>
source§fn execute<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
) -> Result<u64, Error>where
T: ?Sized + ToStatement,
fn execute<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
) -> Result<u64, Error>where
T: ?Sized + ToStatement,
Client::execute
.source§fn query<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
) -> Result<Vec<Row>, Error>where
T: ?Sized + ToStatement,
fn query<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
) -> Result<Vec<Row>, Error>where
T: ?Sized + ToStatement,
Client::query
.source§fn query_one<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
) -> Result<Row, Error>where
T: ?Sized + ToStatement,
fn query_one<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
) -> Result<Row, Error>where
T: ?Sized + ToStatement,
Client::query_one
.source§fn query_opt<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
) -> Result<Option<Row>, Error>where
T: ?Sized + ToStatement,
fn query_opt<T>(
&mut self,
query: &T,
params: &[&(dyn ToSql + Sync)],
) -> Result<Option<Row>, Error>where
T: ?Sized + ToStatement,
Client::query_opt
.source§fn query_raw<T, P, I>(
&mut self,
query: &T,
params: I,
) -> Result<RowIter<'_>, Error>where
T: ?Sized + ToStatement,
P: BorrowToSql,
I: IntoIterator<Item = P>,
I::IntoIter: ExactSizeIterator,
fn query_raw<T, P, I>(
&mut self,
query: &T,
params: I,
) -> Result<RowIter<'_>, Error>where
T: ?Sized + ToStatement,
P: BorrowToSql,
I: IntoIterator<Item = P>,
I::IntoIter: ExactSizeIterator,
Client::query_raw
.source§fn query_typed(
&mut self,
statement: &str,
params: &[(&(dyn ToSql + Sync), Type)],
) -> Result<Vec<Row>, Error>
fn query_typed( &mut self, statement: &str, params: &[(&(dyn ToSql + Sync), Type)], ) -> Result<Vec<Row>, Error>
Client::query_typed
source§fn query_typed_raw<P, I>(
&mut self,
statement: &str,
params: I,
) -> Result<RowIter<'_>, Error>
fn query_typed_raw<P, I>( &mut self, statement: &str, params: I, ) -> Result<RowIter<'_>, Error>
source§fn prepare_typed(
&mut self,
query: &str,
types: &[Type],
) -> Result<Statement, Error>
fn prepare_typed( &mut self, query: &str, types: &[Type], ) -> Result<Statement, Error>
Client::prepare_typed
.source§fn copy_in<T>(&mut self, query: &T) -> Result<CopyInWriter<'_>, Error>where
T: ?Sized + ToStatement,
fn copy_in<T>(&mut self, query: &T) -> Result<CopyInWriter<'_>, Error>where
T: ?Sized + ToStatement,
Client::copy_in
.source§fn copy_out<T>(&mut self, query: &T) -> Result<CopyOutReader<'_>, Error>where
T: ?Sized + ToStatement,
fn copy_out<T>(&mut self, query: &T) -> Result<CopyOutReader<'_>, Error>where
T: ?Sized + ToStatement,
Client::copy_out
.source§fn simple_query(
&mut self,
query: &str,
) -> Result<Vec<SimpleQueryMessage>, Error>
fn simple_query( &mut self, query: &str, ) -> Result<Vec<SimpleQueryMessage>, Error>
Client::simple_query
.source§fn transaction(&mut self) -> Result<Transaction<'_>, Error>
fn transaction(&mut self) -> Result<Transaction<'_>, Error>
Client::transaction
.