Skip to content

Commit 9bc2dae

Browse files
authored
[Cosmos] Remove options builders and (most) impl parameters (Azure#1880)
1 parent 9c1525c commit 9bc2dae

22 files changed

+213
-571
lines changed

sdk/cosmos/azure_data_cosmos/examples/cosmos/create.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ impl CreateCommand {
6666
partition_key,
6767
json,
6868
} => {
69-
let db_client = client.database_client(database);
70-
let container_client = db_client.container_client(container);
69+
let db_client = client.database_client(&database);
70+
let container_client = db_client.container_client(&container);
7171

7272
let pk = PartitionKey::from(&partition_key);
7373
let item: serde_json::Value = serde_json::from_str(&json)?;
@@ -85,7 +85,7 @@ impl CreateCommand {
8585

8686
Subcommands::Database { id } => {
8787
let db = client
88-
.create_database(id, None)
88+
.create_database(&id, None)
8989
.await?
9090
.deserialize_body()
9191
.await?
@@ -110,7 +110,7 @@ impl CreateCommand {
110110
},
111111
};
112112
let container = client
113-
.database_client(database)
113+
.database_client(&database)
114114
.create_container(properties, None)
115115
.await?
116116
.deserialize_body()

sdk/cosmos/azure_data_cosmos/examples/cosmos/delete.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ impl DeleteCommand {
5555
item_id,
5656
partition_key,
5757
} => {
58-
let db_client = client.database_client(database);
59-
let container_client = db_client.container_client(container);
58+
let db_client = client.database_client(&database);
59+
let container_client = db_client.container_client(&container);
6060

6161
let response = container_client
62-
.delete_item(partition_key, item_id, None)
62+
.delete_item(partition_key, &item_id, None)
6363
.await;
6464
match response {
6565
Err(e) if e.http_status() == Some(StatusCode::NotFound) => {
@@ -72,14 +72,14 @@ impl DeleteCommand {
7272
}
7373

7474
Subcommands::Database { id } => {
75-
let db_client = client.database_client(id);
75+
let db_client = client.database_client(&id);
7676
db_client.delete(None).await?;
7777
Ok(())
7878
}
7979

8080
Subcommands::Container { database, id } => {
81-
let db_client = client.database_client(database);
82-
let container_client = db_client.container_client(id);
81+
let db_client = client.database_client(&database);
82+
let container_client = db_client.container_client(&id);
8383
container_client.delete(None).await?;
8484
Ok(())
8585
}

sdk/cosmos/azure_data_cosmos/examples/cosmos/main.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
5454
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
5555
.init();
5656

57-
let args = ProgramArgs::parse();
57+
let mut args = ProgramArgs::parse();
5858

5959
let Some(cmd) = args.subcommand else {
6060
ProgramArgs::command().print_long_help()?;
6161
return Ok(());
6262
};
6363

64-
let client = create_client(&args.shared_args)?;
64+
let client = create_client(&mut args.shared_args)?;
6565

6666
match cmd {
6767
Subcommands::Create(cmd) => cmd.run(client).await,
@@ -78,7 +78,11 @@ fn create_client(args: &SharedArgs) -> Result<CosmosClient, Box<dyn Error>> {
7878
if let Some(key) = args.key.as_ref() {
7979
#[cfg(feature = "key_auth")]
8080
{
81-
Ok(CosmosClient::with_key(&args.endpoint, key.clone(), None)?)
81+
Ok(CosmosClient::with_key(
82+
&args.endpoint,
83+
key.clone().into(),
84+
None,
85+
)?)
8286
}
8387
#[cfg(not(feature = "key_auth"))]
8488
{

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

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
DeleteContainerOptions, ItemOptions, PartitionKey, Query, QueryPartitionStrategy,
1111
};
1212

13-
use azure_core::{Context, Method, Pager, Request, Response};
13+
use azure_core::{Method, Pager, Request, Response};
1414
use serde::{de::DeserializeOwned, Serialize};
1515

1616
/// A client for working with a specific container in a Cosmos DB account.
@@ -60,15 +60,16 @@ impl ContainerClient {
6060
/// ```
6161
pub async fn read(
6262
&self,
63-
64-
#[allow(unused_variables)]
65-
// REASON: This is a documented public API so prefixing with '_' is undesirable.
66-
options: Option<ReadContainerOptions>,
63+
options: Option<ReadContainerOptions<'_>>,
6764
) -> azure_core::Result<Response<ContainerProperties>> {
6865
let url = self.pipeline.url(&self.link);
6966
let mut req = Request::new(url, Method::Get);
7067
self.pipeline
71-
.send(Context::new(), &mut req, self.link.clone())
68+
.send(
69+
options.map(|o| o.method_options.context),
70+
&mut req,
71+
self.link.clone(),
72+
)
7273
.await
7374
}
7475

@@ -80,14 +81,16 @@ impl ContainerClient {
8081
/// * `options` - Optional parameters for the request.
8182
pub async fn delete(
8283
&self,
83-
#[allow(unused_variables)]
84-
// REASON: This is a documented public API so prefixing with '_' is undesirable.
85-
options: Option<DeleteContainerOptions>,
84+
options: Option<DeleteContainerOptions<'_>>,
8685
) -> azure_core::Result<Response> {
8786
let url = self.pipeline.url(&self.link);
8887
let mut req = Request::new(url, Method::Delete);
8988
self.pipeline
90-
.send(Context::new(), &mut req, self.link.clone())
89+
.send(
90+
options.map(|o| o.method_options.context),
91+
&mut req,
92+
self.link.clone(),
93+
)
9194
.await
9295
}
9396

@@ -130,17 +133,18 @@ impl ContainerClient {
130133
&self,
131134
partition_key: impl Into<PartitionKey>,
132135
item: T,
133-
134-
#[allow(unused_variables)]
135-
// REASON: This is a documented public API so prefixing with '_' is undesirable.
136-
options: Option<ItemOptions>,
136+
options: Option<ItemOptions<'_>>,
137137
) -> azure_core::Result<Response<Item<T>>> {
138138
let url = self.pipeline.url(&self.items_link);
139139
let mut req = Request::new(url, Method::Post);
140140
req.insert_headers(&partition_key.into())?;
141141
req.set_json(&item)?;
142142
self.pipeline
143-
.send(Context::new(), &mut req, self.items_link.clone())
143+
.send(
144+
options.map(|o| o.method_options.context),
145+
&mut req,
146+
self.items_link.clone(),
147+
)
144148
.await
145149
}
146150

@@ -183,19 +187,21 @@ impl ContainerClient {
183187
pub async fn replace_item<T: Serialize>(
184188
&self,
185189
partition_key: impl Into<PartitionKey>,
186-
item_id: impl AsRef<str>,
190+
item_id: &str,
187191
item: T,
188192

189193
#[allow(unused_variables)]
190194
// REASON: This is a documented public API so prefixing with '_' is undesirable.
191-
options: Option<ItemOptions>,
195+
options: Option<ItemOptions<'_>>,
192196
) -> azure_core::Result<Response<Item<T>>> {
193197
let link = self.items_link.item(item_id);
194198
let url = self.pipeline.url(&link);
195199
let mut req = Request::new(url, Method::Put);
196200
req.insert_headers(&partition_key.into())?;
197201
req.set_json(&item)?;
198-
self.pipeline.send(Context::new(), &mut req, link).await
202+
self.pipeline
203+
.send(options.map(|o| o.method_options.context), &mut req, link)
204+
.await
199205
}
200206

201207
/// Creates or replaces an item in the container.
@@ -240,18 +246,19 @@ impl ContainerClient {
240246
&self,
241247
partition_key: impl Into<PartitionKey>,
242248
item: T,
243-
244-
#[allow(unused_variables)]
245-
// REASON: This is a documented public API so prefixing with '_' is undesirable.
246-
options: Option<ItemOptions>,
249+
options: Option<ItemOptions<'_>>,
247250
) -> azure_core::Result<Response<Item<T>>> {
248251
let url = self.pipeline.url(&self.items_link);
249252
let mut req = Request::new(url, Method::Post);
250253
req.insert_header(constants::IS_UPSERT, "true");
251254
req.insert_headers(&partition_key.into())?;
252255
req.set_json(&item)?;
253256
self.pipeline
254-
.send(Context::new(), &mut req, self.items_link.clone())
257+
.send(
258+
options.map(|o| o.method_options.context),
259+
&mut req,
260+
self.items_link.clone(),
261+
)
255262
.await
256263
}
257264

@@ -288,17 +295,16 @@ impl ContainerClient {
288295
pub async fn read_item<T: DeserializeOwned>(
289296
&self,
290297
partition_key: impl Into<PartitionKey>,
291-
item_id: impl AsRef<str>,
292-
293-
#[allow(unused_variables)]
294-
// REASON: This is a documented public API so prefixing with '_' is undesirable.
295-
options: Option<ItemOptions>,
298+
item_id: &str,
299+
options: Option<ItemOptions<'_>>,
296300
) -> azure_core::Result<Response<Item<T>>> {
297301
let link = self.items_link.item(item_id);
298302
let url = self.pipeline.url(&link);
299303
let mut req = Request::new(url, Method::Get);
300304
req.insert_headers(&partition_key.into())?;
301-
self.pipeline.send(Context::new(), &mut req, link).await
305+
self.pipeline
306+
.send(options.map(|o| o.method_options.context), &mut req, link)
307+
.await
302308
}
303309

304310
/// Deletes an item from the container.
@@ -323,17 +329,16 @@ impl ContainerClient {
323329
pub async fn delete_item(
324330
&self,
325331
partition_key: impl Into<PartitionKey>,
326-
item_id: impl AsRef<str>,
327-
328-
#[allow(unused_variables)]
329-
// REASON: This is a documented public API so prefixing with '_' is undesirable.
330-
options: Option<ItemOptions>,
332+
item_id: &str,
333+
options: Option<ItemOptions<'_>>,
331334
) -> azure_core::Result<Response> {
332335
let link = self.items_link.item(item_id);
333336
let url = self.pipeline.url(&link);
334337
let mut req = Request::new(url, Method::Delete);
335338
req.insert_headers(&partition_key.into())?;
336-
self.pipeline.send(Context::new(), &mut req, link).await
339+
self.pipeline
340+
.send(options.map(|o| o.method_options.context), &mut req, link)
341+
.await
337342
}
338343

339344
/// Executes a single-partition query against items in the container.
@@ -394,17 +399,18 @@ impl ContainerClient {
394399
&self,
395400
query: impl Into<Query>,
396401
partition_key: impl Into<QueryPartitionStrategy>,
397-
398-
#[allow(unused_variables)]
399-
// REASON: This is a documented public API so prefixing with '_' is undesirable.
400-
options: Option<QueryOptions>,
402+
options: Option<QueryOptions<'_>>,
401403
) -> azure_core::Result<Pager<QueryResults<T>>> {
402404
let url = self.pipeline.url(&self.items_link);
403405
let mut base_request = Request::new(url, Method::Post);
404406
let QueryPartitionStrategy::SinglePartition(partition_key) = partition_key.into();
405407
base_request.insert_headers(&partition_key)?;
406408

407-
self.pipeline
408-
.send_query_request(query.into(), base_request, self.items_link.clone())
409+
self.pipeline.send_query_request(
410+
options.map(|o| o.method_options.context),
411+
query.into(),
412+
base_request,
413+
self.items_link.clone(),
414+
)
409415
}
410416
}

0 commit comments

Comments
 (0)