pub struct WriteOnlyTransaction { /* private fields */ }Expand description
A write-only transaction.
A write-only transaction can be used to execute blind writes.
Implementations§
Source§impl WriteOnlyTransaction
impl WriteOnlyTransaction
Sourcepub async fn write<I>(self, mutations: I) -> Result<CommitResponse>where
I: IntoIterator<Item = Mutation>,
pub async fn write<I>(self, mutations: I) -> Result<CommitResponse>where
I: IntoIterator<Item = Mutation>,
Writes a set of mutations atomically to Spanner.
§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)
.set("UserName").to(&"Alice")
.build();
let response = db.write_only_transaction()
.set_transaction_tag("my-tag")
.build()
.write(vec![mutation])
.await?;This method uses retries and replay protection internally, which means that the mutations are applied exactly once on success, or not at all if an error is returned, regardless of any failures in the underlying network. Note that if the call is cancelled or reaches deadline, it is not possible to know whether the mutations were applied without performing a subsequent database operation, but the mutations will have been applied at most once.
Sourcepub async fn write_at_least_once<I>(
self,
mutations: I,
) -> Result<CommitResponse>where
I: IntoIterator<Item = Mutation>,
pub async fn write_at_least_once<I>(
self,
mutations: I,
) -> Result<CommitResponse>where
I: IntoIterator<Item = Mutation>,
Writes a set of mutations at least once using a single Commit RPC.
§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_or_update_builder("Users")
.set("UserId").to(&1)
.set("UserName").to(&"Alice")
.build();
let response = db.write_only_transaction()
.set_transaction_tag("my-tag")
.build()
.write_at_least_once(vec![mutation])
.await?;Since this method does not feature replay protection, it may attempt to apply the provided
mutations more than once. If the mutations are not idempotent, this may lead to a failure
being reported even if the mutation was applied successfully the first time. For example,
an insert may fail with an AlreadyExists error even though the row did not exist before
this method was called. For this reason, most users of the library will prefer to use write
transactions with replay protection instead.
However, write_at_least_once requires only a single RPC, whereas replay-protected
writes require two RPCs. Thus, this method may be appropriate for latency sensitive
and/or high throughput blind writing.
Auto Trait Implementations§
impl !RefUnwindSafe for WriteOnlyTransaction
impl !UnwindSafe for WriteOnlyTransaction
impl Freeze for WriteOnlyTransaction
impl Send for WriteOnlyTransaction
impl Sync for WriteOnlyTransaction
impl Unpin for WriteOnlyTransaction
impl UnsafeUnpin for WriteOnlyTransaction
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
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>
T in a tonic::Request