Struct madsim_tokio_postgres::Transaction
source · [−]pub struct Transaction<'a> { /* private fields */ }
Expand description
A representation of a PostgreSQL database transaction.
Transactions will implicitly roll back when dropped. Use the commit
method to commit the changes made in the
transaction. Transactions can be nested, with inner transactions implemented via safepoints.
Implementations
sourceimpl<'a> Transaction<'a>
impl<'a> Transaction<'a>
sourcepub async fn commit(self) -> Result<(), Error>
pub async fn commit(self) -> Result<(), Error>
Consumes the transaction, committing all changes made within it.
sourcepub async fn rollback(self) -> Result<(), Error>
pub async 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 async fn prepare_typed(
&self,
query: &str,
parameter_types: &[Type]
) -> Result<Statement, Error>
pub async fn prepare_typed(
&self,
query: &str,
parameter_types: &[Type]
) -> Result<Statement, Error>
Like Client::prepare_typed
.
sourcepub async fn query<T>(
&self,
statement: &T,
params: &[&(dyn ToSql + Sync)]
) -> Result<Vec<Row>, Error> where
T: ?Sized + ToStatement,
pub async fn query<T>(
&self,
statement: &T,
params: &[&(dyn ToSql + Sync)]
) -> Result<Vec<Row>, Error> where
T: ?Sized + ToStatement,
Like Client::query
.
sourcepub async fn query_one<T>(
&self,
statement: &T,
params: &[&(dyn ToSql + Sync)]
) -> Result<Row, Error> where
T: ?Sized + ToStatement,
pub async fn query_one<T>(
&self,
statement: &T,
params: &[&(dyn ToSql + Sync)]
) -> Result<Row, Error> where
T: ?Sized + ToStatement,
Like Client::query_one
.
sourcepub async fn query_opt<T>(
&self,
statement: &T,
params: &[&(dyn ToSql + Sync)]
) -> Result<Option<Row>, Error> where
T: ?Sized + ToStatement,
pub async fn query_opt<T>(
&self,
statement: &T,
params: &[&(dyn ToSql + Sync)]
) -> Result<Option<Row>, Error> where
T: ?Sized + ToStatement,
Like Client::query_opt
.
sourcepub async fn query_raw<T, P, I>(
&self,
statement: &T,
params: I
) -> Result<RowStream, Error> where
T: ?Sized + ToStatement,
P: BorrowToSql,
I: IntoIterator<Item = P>,
I::IntoIter: ExactSizeIterator,
pub async fn query_raw<T, P, I>(
&self,
statement: &T,
params: I
) -> Result<RowStream, Error> where
T: ?Sized + ToStatement,
P: BorrowToSql,
I: IntoIterator<Item = P>,
I::IntoIter: ExactSizeIterator,
Like Client::query_raw
.
sourcepub async fn execute<T>(
&self,
statement: &T,
params: &[&(dyn ToSql + Sync)]
) -> Result<u64, Error> where
T: ?Sized + ToStatement,
pub async fn execute<T>(
&self,
statement: &T,
params: &[&(dyn ToSql + Sync)]
) -> Result<u64, Error> where
T: ?Sized + ToStatement,
Like Client::execute
.
sourcepub async fn execute_raw<P, I, T>(
&self,
statement: &T,
params: I
) -> Result<u64, Error> where
T: ?Sized + ToStatement,
P: BorrowToSql,
I: IntoIterator<Item = P>,
I::IntoIter: ExactSizeIterator,
pub async fn execute_raw<P, I, T>(
&self,
statement: &T,
params: I
) -> Result<u64, Error> where
T: ?Sized + ToStatement,
P: BorrowToSql,
I: IntoIterator<Item = P>,
I::IntoIter: ExactSizeIterator,
Like Client::execute_iter
.
sourcepub async fn bind<T>(
&self,
statement: &T,
params: &[&(dyn ToSql + Sync)]
) -> Result<Portal, Error> where
T: ?Sized + ToStatement,
pub async fn bind<T>(
&self,
statement: &T,
params: &[&(dyn ToSql + Sync)]
) -> Result<Portal, Error> where
T: ?Sized + ToStatement,
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.
sourcepub async fn bind_raw<P, T, I>(
&self,
statement: &T,
params: I
) -> Result<Portal, Error> where
T: ?Sized + ToStatement,
P: BorrowToSql,
I: IntoIterator<Item = P>,
I::IntoIter: ExactSizeIterator,
pub async fn bind_raw<P, T, I>(
&self,
statement: &T,
params: I
) -> Result<Portal, Error> where
T: ?Sized + ToStatement,
P: BorrowToSql,
I: IntoIterator<Item = P>,
I::IntoIter: ExactSizeIterator,
A maximally flexible version of bind
.
sourcepub async fn query_portal(
&self,
portal: &Portal,
max_rows: i32
) -> Result<Vec<Row>, Error>
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.
sourcepub async fn query_portal_raw(
&self,
portal: &Portal,
max_rows: i32
) -> Result<RowStream, Error>
pub async fn query_portal_raw(
&self,
portal: &Portal,
max_rows: i32
) -> Result<RowStream, Error>
The maximally flexible version of query_portal
.
sourcepub async fn copy_in<T, U>(&self, statement: &T) -> Result<CopyInSink<U>, Error> where
T: ?Sized + ToStatement,
U: Buf + 'static + Send,
pub async fn copy_in<T, U>(&self, statement: &T) -> Result<CopyInSink<U>, Error> where
T: ?Sized + ToStatement,
U: Buf + 'static + Send,
Like Client::copy_in
.
sourcepub async fn copy_out<T>(&self, statement: &T) -> Result<CopyOutStream, Error> where
T: ?Sized + ToStatement,
pub async fn copy_out<T>(&self, statement: &T) -> Result<CopyOutStream, Error> where
T: ?Sized + ToStatement,
Like Client::copy_out
.
sourcepub async fn simple_query(
&self,
query: &str
) -> Result<Vec<SimpleQueryMessage>, Error>
pub async fn simple_query(
&self,
query: &str
) -> Result<Vec<SimpleQueryMessage>, Error>
Like Client::simple_query
.
sourcepub async fn batch_execute(&self, query: &str) -> Result<(), Error>
pub async fn batch_execute(&self, query: &str) -> Result<(), Error>
Like Client::batch_execute
.
sourcepub fn cancel_token(&self) -> CancelToken
pub fn cancel_token(&self) -> CancelToken
Like Client::cancel_token
.
sourcepub async fn cancel_query<T>(&self, tls: T) -> Result<(), Error> where
T: MakeTlsConnect<Socket>,
👎 Deprecated since 0.6.0: use Transaction::cancel_token() instead
pub async fn cancel_query<T>(&self, tls: T) -> Result<(), Error> where
T: MakeTlsConnect<Socket>,
use Transaction::cancel_token() instead
Like Client::cancel_query
.
sourcepub 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
pub async fn cancel_query_raw<S, T>(&self, stream: S, tls: T) -> Result<(), Error> where
S: AsyncRead + AsyncWrite + Unpin,
T: TlsConnect<S>,
use Transaction::cancel_token() instead
Like Client::cancel_query_raw
.
sourcepub async fn transaction(&mut self) -> Result<Transaction<'_>, Error>
pub async 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<'impl0> GenericClient for Transaction<'impl0>
impl<'impl0> GenericClient for Transaction<'impl0>
sourcefn execute<'life0, 'life1, 'life2, 'life3, 'async_trait, T>(
&'life0 self,
query: &'life1 T,
params: &'life2 [&'life3 (dyn ToSql + Sync)]
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>> where
T: ?Sized + ToStatement + Sync + Send,
T: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn execute<'life0, 'life1, 'life2, 'life3, 'async_trait, T>(
&'life0 self,
query: &'life1 T,
params: &'life2 [&'life3 (dyn ToSql + Sync)]
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>> where
T: ?Sized + ToStatement + Sync + Send,
T: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Like Client::execute
.
sourcefn execute_raw<'life0, 'life1, 'async_trait, P, I, T>(
&'life0 self,
statement: &'life1 T,
params: I
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>> where
T: ?Sized + ToStatement + Sync + Send,
P: BorrowToSql,
I: IntoIterator<Item = P> + Sync + Send,
I::IntoIter: ExactSizeIterator,
P: 'async_trait,
I: 'async_trait,
T: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn execute_raw<'life0, 'life1, 'async_trait, P, I, T>(
&'life0 self,
statement: &'life1 T,
params: I
) -> Pin<Box<dyn Future<Output = Result<u64, Error>> + Send + 'async_trait>> where
T: ?Sized + ToStatement + Sync + Send,
P: BorrowToSql,
I: IntoIterator<Item = P> + Sync + Send,
I::IntoIter: ExactSizeIterator,
P: 'async_trait,
I: 'async_trait,
T: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Like Client::execute_raw
.
sourcefn query<'life0, 'life1, 'life2, 'life3, 'async_trait, T>(
&'life0 self,
query: &'life1 T,
params: &'life2 [&'life3 (dyn ToSql + Sync)]
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, Error>> + Send + 'async_trait>> where
T: ?Sized + ToStatement + Sync + Send,
T: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn query<'life0, 'life1, 'life2, 'life3, 'async_trait, T>(
&'life0 self,
query: &'life1 T,
params: &'life2 [&'life3 (dyn ToSql + Sync)]
) -> Pin<Box<dyn Future<Output = Result<Vec<Row>, Error>> + Send + 'async_trait>> where
T: ?Sized + ToStatement + Sync + Send,
T: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Like Client::query
.
sourcefn query_one<'life0, 'life1, 'life2, 'life3, 'async_trait, T>(
&'life0 self,
statement: &'life1 T,
params: &'life2 [&'life3 (dyn ToSql + Sync)]
) -> Pin<Box<dyn Future<Output = Result<Row, Error>> + Send + 'async_trait>> where
T: ?Sized + ToStatement + Sync + Send,
T: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn query_one<'life0, 'life1, 'life2, 'life3, 'async_trait, T>(
&'life0 self,
statement: &'life1 T,
params: &'life2 [&'life3 (dyn ToSql + Sync)]
) -> Pin<Box<dyn Future<Output = Result<Row, Error>> + Send + 'async_trait>> where
T: ?Sized + ToStatement + Sync + Send,
T: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Like Client::query_one
.
sourcefn query_opt<'life0, 'life1, 'life2, 'life3, 'async_trait, T>(
&'life0 self,
statement: &'life1 T,
params: &'life2 [&'life3 (dyn ToSql + Sync)]
) -> Pin<Box<dyn Future<Output = Result<Option<Row>, Error>> + Send + 'async_trait>> where
T: ?Sized + ToStatement + Sync + Send,
T: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn query_opt<'life0, 'life1, 'life2, 'life3, 'async_trait, T>(
&'life0 self,
statement: &'life1 T,
params: &'life2 [&'life3 (dyn ToSql + Sync)]
) -> Pin<Box<dyn Future<Output = Result<Option<Row>, Error>> + Send + 'async_trait>> where
T: ?Sized + ToStatement + Sync + Send,
T: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Like Client::query_opt
.
sourcefn query_raw<'life0, 'life1, 'async_trait, T, P, I>(
&'life0 self,
statement: &'life1 T,
params: I
) -> Pin<Box<dyn Future<Output = Result<RowStream, Error>> + Send + 'async_trait>> where
T: ?Sized + ToStatement + Sync + Send,
P: BorrowToSql,
I: IntoIterator<Item = P> + Sync + Send,
I::IntoIter: ExactSizeIterator,
T: 'async_trait,
P: 'async_trait,
I: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn query_raw<'life0, 'life1, 'async_trait, T, P, I>(
&'life0 self,
statement: &'life1 T,
params: I
) -> Pin<Box<dyn Future<Output = Result<RowStream, Error>> + Send + 'async_trait>> where
T: ?Sized + ToStatement + Sync + Send,
P: BorrowToSql,
I: IntoIterator<Item = P> + Sync + Send,
I::IntoIter: ExactSizeIterator,
T: 'async_trait,
P: 'async_trait,
I: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Like Client::query_raw
.
sourcefn prepare<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Statement, Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn prepare<'life0, 'life1, 'async_trait>(
&'life0 self,
query: &'life1 str
) -> Pin<Box<dyn Future<Output = Result<Statement, Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Like Client::prepare
.
sourcefn prepare_typed<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
query: &'life1 str,
parameter_types: &'life2 [Type]
) -> Pin<Box<dyn Future<Output = Result<Statement, Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn prepare_typed<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
query: &'life1 str,
parameter_types: &'life2 [Type]
) -> Pin<Box<dyn Future<Output = Result<Statement, Error>> + Send + 'async_trait>> where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Like Client::prepare_typed
.
sourcefn transaction<'a, 'async_trait>(
&'a mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'a>, Error>> + Send + 'async_trait>> where
'a: 'async_trait,
Self: 'async_trait,
fn transaction<'a, 'async_trait>(
&'a mut self
) -> Pin<Box<dyn Future<Output = Result<Transaction<'a>, Error>> + Send + 'async_trait>> where
'a: 'async_trait,
Self: 'async_trait,
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