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
sourceimpl<'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 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
sourceimpl<'a> Drop for Transaction<'a>
impl<'a> Drop for Transaction<'a>
sourceimpl GenericClient for Transaction<'_>
impl GenericClient for Transaction<'_>
sourcefn 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,
Like Client::execute
.
sourcefn 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,
Like Client::query
.
sourcefn 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,
Like Client::query_one
.
sourcefn 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,
Like Client::query_opt
.
sourcefn 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,
Like Client::query_raw
.
sourcefn prepare_typed(
&mut self,
query: &str,
types: &[Type]
) -> Result<Statement, Error>
fn prepare_typed(
&mut self,
query: &str,
types: &[Type]
) -> Result<Statement, Error>
Like Client::prepare_typed
.
sourcefn 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,
Like Client::copy_in
.
sourcefn 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,
Like Client::copy_out
.
sourcefn simple_query(&mut self, query: &str) -> Result<Vec<SimpleQueryMessage>, Error>
fn simple_query(&mut self, query: &str) -> Result<Vec<SimpleQueryMessage>, Error>
Like Client::simple_query
.
sourcefn transaction(&mut self) -> Result<Transaction<'_>, Error>
fn transaction(&mut self) -> Result<Transaction<'_>, Error>
Like Client::transaction
.
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more