pub struct BatchWriteTransaction { /* private fields */ }Expand description
A transaction for executing batch writes.
Batch writes are not guaranteed to be atomic across mutation groups. All mutations within a group are applied atomically.
Implementations§
Source§impl BatchWriteTransaction
impl BatchWriteTransaction
Sourcepub async fn execute_streaming<I>(
self,
groups: I,
) -> Result<BatchWriteResponseStream>where
I: IntoIterator<Item = MutationGroup>,
pub async fn execute_streaming<I>(
self,
groups: I,
) -> Result<BatchWriteResponseStream>where
I: IntoIterator<Item = MutationGroup>,
Executes the batch write and returns a stream of responses.
§Example
let client = Spanner::builder().build().await?;
let db = client.database_client("projects/p/instances/i/databases/d").build().await?;
let mutation = Mutation::new_insert_builder("Users")
.set("UserId").to(&1)
.build();
let group = MutationGroup::new(vec![mutation]);
let tx = db.batch_write_transaction().build();
let mut stream = tx.execute_streaming(vec![group]).await?;
while let Some(response) = stream.next().await {
let response = response?;
if let Some(status) = response.status.as_ref().filter(|s| s.code != Code::Ok as i32) {
eprintln!("Error applying groups {:?}: {}", response.indexes, status.message);
} else {
println!("Applied groups: {:?}", response.indexes);
}
}This method sends the mutation groups to Spanner and returns the responses as a stream. Each response includes a status code that indicates whether the mutation groups that it references were applied successfully.
The method does not handle any errors, including retryable errors like Aborted. The caller is responsible for handling any errors and for retrying the transaction in case it is aborted by Spanner.
Auto Trait Implementations§
impl !RefUnwindSafe for BatchWriteTransaction
impl !UnwindSafe for BatchWriteTransaction
impl Freeze for BatchWriteTransaction
impl Send for BatchWriteTransaction
impl Sync for BatchWriteTransaction
impl Unpin for BatchWriteTransaction
impl UnsafeUnpin for BatchWriteTransaction
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