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 database_client = spanner
.database_client("projects/p/instances/i/databases/d")
.build()
.await?;
let runner = database_client.read_write_transaction().build();
let transaction_result = runner
.run(async |transaction| {
let statement = Statement::builder(
"UPDATE MyTable SET MyColumn = 'MyValue' WHERE Id = 1",
)
.build();
let updated_rows = transaction.execute_update(statement).await?;
Ok(updated_rows)
})
.await?;
println!("Updated {} rows", transaction_result.result);Returns a TransactionResult containing both the user-defined result value
and the CommitResponse on success.
The transaction is automatically committed if the closure returns Ok.
If the closure returns Err, the transaction is rolled back and the error is propagated.
If the transaction is aborted by Spanner due to concurrency contention, the closure
is automatically retried according to the configured TransactionRetryPolicy.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for TransactionRunner
impl !RefUnwindSafe for TransactionRunner
impl !UnwindSafe for TransactionRunner
impl Forget for TransactionRunner
impl Move 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