Skip to content

Commit 95eff26

Browse files
gsa9989heaths
andauthored
Added if_match_etag to Item Options (Azure#2705)
* read me change * if_match_etag changes with tests * if_match_etag changes with tests * test changes * if_match_etag added with tests * changing back test_accounts file * test changes and small fixes * change log and url fixes * comment changes * added test recordings * changed changelog * Update sdk/cosmos/azure_data_cosmos/CHANGELOG.md Co-authored-by: Heath Stewart <[email protected]> --------- Co-authored-by: Heath Stewart <[email protected]>
1 parent 2a9453b commit 95eff26

File tree

6 files changed

+312
-6
lines changed

6 files changed

+312
-6
lines changed

sdk/cosmos/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "rust",
4-
"Tag": "rust/azure_data_cosmos_ff23846344",
4+
"Tag": "rust/azure_data_cosmos_a39b424a5b",
55
"TagPrefix": "rust/azure_data_cosmos"
66
}

sdk/cosmos/azure_data_cosmos/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 0.25.0 (Unreleased)
44

55
### Features Added
6+
* Added `if_match_etag` to `ItemOptions` ([#2705](https://github.com/Azure/azure-sdk-for-rust/pull/2705))
67

78
### Breaking Changes
89

sdk/cosmos/azure_data_cosmos/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ async fn example(cosmos_client: CosmosClient) -> Result<(), Box<dyn std::error::
131131
* [Partitioning](https://learn.microsoft.com/azure/cosmos-db/partition-data)
132132
* [Using emulator](https://github.com/Azure/azure-documentdb-dotnet/blob/master/docs/documentdb-nosql-local-emulator.md)
133133

134-
## Next steps
135-
136134
### Provide feedback
137135

138136
If you encounter bugs or have suggestions, [open an issue](https://github.com/Azure/azure-sdk-for-rust/issues).

sdk/cosmos/azure_data_cosmos/src/clients/container_client.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
};
1313

1414
use azure_core::http::{
15-
headers,
15+
headers::{self},
1616
request::{options::ContentType, Request},
1717
response::Response,
1818
Method,
@@ -358,6 +358,9 @@ impl ContainerClient {
358358
if !options.enable_content_response_on_write {
359359
req.insert_header(headers::PREFER, constants::PREFER_MINIMAL);
360360
}
361+
if let Some(etag) = options.if_match_etag {
362+
req.insert_header(headers::IF_MATCH, etag);
363+
}
361364
req.insert_headers(&partition_key.into())?;
362365
req.insert_headers(&ContentType::APPLICATION_JSON)?;
363366
req.set_json(&item)?;
@@ -447,6 +450,9 @@ impl ContainerClient {
447450
if !options.enable_content_response_on_write {
448451
req.insert_header(headers::PREFER, constants::PREFER_MINIMAL);
449452
}
453+
if let Some(etag) = options.if_match_etag {
454+
req.insert_header(headers::IF_MATCH, etag);
455+
}
450456
req.insert_header(constants::IS_UPSERT, "true");
451457
req.insert_headers(&partition_key.into())?;
452458
req.insert_headers(&ContentType::APPLICATION_JSON)?;
@@ -537,6 +543,9 @@ impl ContainerClient {
537543
let link = self.items_link.item(item_id);
538544
let url = self.pipeline.url(&link);
539545
let mut req = Request::new(url, Method::Delete);
546+
if let Some(etag) = options.if_match_etag {
547+
req.insert_header(headers::IF_MATCH, etag);
548+
}
540549
req.insert_headers(&partition_key.into())?;
541550
self.pipeline
542551
.send(options.method_options.context, &mut req, link)
@@ -613,6 +622,9 @@ impl ContainerClient {
613622
if !options.enable_content_response_on_write {
614623
req.insert_header(headers::PREFER, constants::PREFER_MINIMAL);
615624
}
625+
if let Some(etag) = options.if_match_etag {
626+
req.insert_header(headers::IF_MATCH, etag);
627+
}
616628
req.insert_headers(&partition_key.into())?;
617629
req.insert_headers(&ContentType::APPLICATION_JSON)?;
618630
req.set_json(&patch)?;

sdk/cosmos/azure_data_cosmos/src/options/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
use azure_core::http::{ClientMethodOptions, ClientOptions};
4+
use azure_core::http::{ClientMethodOptions, ClientOptions, Etag};
55

66
use crate::models::ThroughputProperties;
77

@@ -47,7 +47,10 @@ pub struct DeleteDatabaseOptions<'a> {
4747
#[derive(Clone, Default)]
4848
pub struct ItemOptions<'a> {
4949
pub method_options: ClientMethodOptions<'a>,
50-
50+
/// If specified, the operation will only be performed if the item matches the provided Etag.
51+
///
52+
/// See [Optimistic Concurrency Control](https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/database-transactions-optimistic-concurrency#optimistic-concurrency-control) for more.
53+
pub if_match_etag: Option<Etag>,
5154
/// When this value is true, write operations will respond with the new value of the resource being written.
5255
///
5356
/// The default for this is `false`, which reduces the network and CPU burden that comes from serializing and deserializing the response.

0 commit comments

Comments
 (0)