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(
self,
mutation_groups: impl IntoIterator<Item = MutationGroup>,
) -> Result<BatchWriteResponseStream>
pub async fn execute_streaming( self, mutation_groups: impl IntoIterator<Item = MutationGroup>, ) -> Result<BatchWriteResponseStream>
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 transaction = db.batch_write_transaction().build();
let mut stream = transaction.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.
Transient network or server errors during stream creation or iteration are automatically retried according to the configured retry and backoff policies. Upon retry, already-processed mutation groups are not resent, and returned response indices always refer to the caller’s original input slice.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for BatchWriteTransaction
impl !RefUnwindSafe for BatchWriteTransaction
impl !UnwindSafe for BatchWriteTransaction
impl Forget for BatchWriteTransaction
impl Move 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