pub struct TransactionRunner { /* private fields */ }Expand description
A runner for read/write transactions. Aborted transactions are automatically retried.
Implementations§
Source§impl TransactionRunner
impl TransactionRunner
Sourcepub async fn run<T, F>(self, work: F) -> Result<TransactionResult<T>>
pub async fn run<T, F>(self, work: F) -> Result<TransactionResult<T>>
Runs the provided closure within the context of a read/write transaction.
§Example
let db_client = client.database_client("projects/p/instances/i/databases/d").build().await?;
let runner = db_client.read_write_transaction().build().await?;
let result = runner.run(async |transaction| {
let statement = Statement::builder("UPDATE MyTable SET MyColumn = 'MyValue' WHERE Id = 1").build();
transaction.execute_update(statement).await?;
Ok(42)
}).await?;If the transaction is aborted by Spanner, the closure will be retried
automatically according to the configured TransactionRetryPolicy.
The transaction is automatically committed if the closure returns Ok.
If the closure returns Err, the transaction will be rolled back and
the error will be propagated.
Auto Trait Implementations§
impl !RefUnwindSafe for TransactionRunner
impl !UnwindSafe for TransactionRunner
impl Freeze for TransactionRunner
impl Send for TransactionRunner
impl Sync for TransactionRunner
impl Unpin for TransactionRunner
impl UnsafeUnpin for TransactionRunner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request