Skip to content

Remove context as a parameter the user provides #474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions sdk/cosmos/examples/attachments_00.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use azure_core::Context;
use azure_cosmos::prelude::*;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
Expand Down Expand Up @@ -58,7 +57,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {

// let's add an entity.
match client
.create_document(Context::new(), &doc, CreateDocumentOptions::new())
.create_document(&doc, CreateDocumentOptions::new())
.await
{
Ok(_) => {
Expand Down
5 changes: 2 additions & 3 deletions sdk/cosmos/examples/cancellation.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use azure_core::prelude::*;
use azure_cosmos::prelude::*;
use stop_token::prelude::*;
use stop_token::StopSource;
Expand All @@ -20,7 +19,7 @@ async fn main() -> azure_cosmos::Result<()> {

// Create a new database, and time out if it takes more than 1 second.
let options = CreateDatabaseOptions::new();
let future = client.create_database(Context::new(), "my_database", options);
let future = client.create_database("my_database", options);
let deadline = Instant::now() + Duration::from_secs(1);
match future.until(deadline).await {
Ok(Ok(r)) => println!("successful response: {:?}", r),
Expand All @@ -37,7 +36,7 @@ async fn main() -> azure_cosmos::Result<()> {
let stop = source.token();
tokio::spawn(async move {
let options = CreateDatabaseOptions::new();
let future = client.create_database(Context::new(), "my_database", options);
let future = client.create_database("my_database", options);
match future.until(stop).await {
Ok(Ok(r)) => println!("successful response: {:?}", r),
Ok(Err(e)) => println!("request was made but failed: {:?}", e),
Expand Down
8 changes: 4 additions & 4 deletions sdk/cosmos/examples/collection.rs.disabled
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use azure_core::prelude::*;

use azure_cosmos::prelude::*;
use futures::stream::StreamExt;
use std::error::Error;
Expand Down Expand Up @@ -34,7 +34,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
// The Cosmos' client exposes a lot of methods. This one lists the databases in the specified
// account. Database do not implement Display but deref to &str so you can pass it to methods
// both as struct or id.
let databases = Box::pin(client.list_databases(Context::new(), ListDatabasesOptions::new()))
let databases = Box::pin(client.list_databases(ListDatabasesOptions::new()))
.next()
.await
.unwrap()?;
Expand All @@ -51,7 +51,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let db = client
.clone()
.into_database_client(db.id.clone())
.get_database(Context::new(), GetDatabaseOptions::default())
.get_database(GetDatabaseOptions::default())
.await?;
println!("db {} found == {:?}", &db.database.id, &db);
}
Expand All @@ -74,7 +74,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let collection_response = database_client
.clone()
.into_collection_client(collection.id)
.get_collection(Context::new(), GetCollectionOptions::new())
.get_collection(GetCollectionOptions::new())
.await?;

println!("\tcollection_response {:?}", collection_response);
Expand Down
12 changes: 6 additions & 6 deletions sdk/cosmos/examples/create_delete_database.rs.disabled
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use azure_core::Context;

use azure_cosmos::prelude::*;
use futures::stream::StreamExt;
use std::error::Error;
Expand Down Expand Up @@ -37,14 +37,14 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
// both as struct or id.

let mut list_databases_stream =
Box::pin(client.list_databases(Context::new(), ListDatabasesOptions::new()));
Box::pin(client.list_databases(ListDatabasesOptions::new()));
while let Some(list_databases_response) = list_databases_stream.next().await {
println!("list_databases_response = {:#?}", list_databases_response?);
}
drop(list_databases_stream);

let db = client
.create_database(Context::new(), &database_name, CreateDatabaseOptions::new())
.create_database(&database_name, CreateDatabaseOptions::new())
.await?;
println!("created database = {:#?}", db);

Expand All @@ -54,7 +54,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {

let create_collection_response = db_client
.create_collection(
Context::new(),

"panzadoro",
CreateCollectionOptions::new("/id"),
)
Expand All @@ -68,7 +68,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let db_collection = db_client.clone().into_collection_client("panzadoro");

let get_collection_response = db_collection
.get_collection(Context::new(), GetCollectionOptions::new())
.get_collection(GetCollectionOptions::new())
.await?;
println!("get_collection_response == {:#?}", get_collection_response);

Expand All @@ -80,7 +80,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
}

let delete_response = db_collection
.delete_collection(Context::new(), DeleteCollectionOptions::new())
.delete_collection(DeleteCollectionOptions::new())
.await?;
println!("collection deleted: {:#?}", delete_response);
}
Expand Down
8 changes: 4 additions & 4 deletions sdk/cosmos/examples/database_00.rs.disabled
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use azure_core::Context;

use azure_cosmos::prelude::*;
use futures::stream::StreamExt;
use serde_json::Value;
Expand All @@ -16,7 +16,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {

let client = CosmosClient::new(account, authorization_token, CosmosOptions::default());

let dbs = Box::pin(client.list_databases(Context::new(), ListDatabasesOptions::new()))
let dbs = Box::pin(client.list_databases(ListDatabasesOptions::new()))
.next()
.await
.unwrap()?;
Expand Down Expand Up @@ -50,7 +50,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
.partition_key(&43u32)
.unwrap();
let resp = collection_client
.create_document(Context::new(), &document, options)
.create_document(&document, options)
.await?;

println!("resp == {:?}", resp);
Expand All @@ -64,7 +64,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
println!("\nReplacing collection");
let replace_collection_response = collection_client
.replace_collection(
Context::new(),

ReplaceCollectionOptions::new("/age").indexing_policy(indexing_policy_new),
)
.await?;
Expand Down
12 changes: 5 additions & 7 deletions sdk/cosmos/examples/database_01.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use azure_core::Context;
use azure_cosmos::prelude::*;
use futures::stream::StreamExt;
use std::error::Error;
Expand All @@ -18,16 +17,15 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let database_client = client.into_database_client("pollo");
println!("database_name == {}", database_client.database_name());

let collections =
Box::pin(database_client.list_collections(Context::new(), ListCollectionsOptions::new()))
.next()
.await
.unwrap()?;
let collections = Box::pin(database_client.list_collections(ListCollectionsOptions::new()))
.next()
.await
.unwrap()?;
println!("collections == {:#?}", collections);

let collection_client = database_client.into_collection_client("cnt");
let collection = collection_client
.get_collection(Context::new(), GetCollectionOptions::new())
.get_collection(GetCollectionOptions::new())
.await?;
println!("collection == {:#?}", collection);

Expand Down
14 changes: 7 additions & 7 deletions sdk/cosmos/examples/document_00.rs.disabled
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use futures::stream::StreamExt;
use serde::{Deserialize, Serialize};
// Using the prelude module of the Cosmos crate makes easier to use the Rust Azure SDK for Cosmos
// DB.
use azure_core::prelude::*;

use azure_cosmos::prelude::*;
use std::borrow::Cow;
use std::error::Error;
Expand Down Expand Up @@ -57,7 +57,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
// an error (for example, the given key is not valid) you will receive a
// specific azure_cosmos::Error. In this example we will look for a specific database
// so we chain a filter operation.
let db = Box::pin(client.list_databases(Context::new(), ListDatabasesOptions::new()))
let db = Box::pin(client.list_databases(ListDatabasesOptions::new()))
.next()
.await
.unwrap()?
Expand All @@ -70,7 +70,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
Some(db) => db,
None => {
client
.create_database(Context::new(), DATABASE, CreateDatabaseOptions::new())
.create_database(DATABASE, CreateDatabaseOptions::new())
.await?
.database
}
Expand Down Expand Up @@ -99,7 +99,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
.clone()
.into_database_client(database.id.clone())
.create_collection(
Context::new(),

COLLECTION,
CreateCollectionOptions::new("/id"),
)
Expand Down Expand Up @@ -131,7 +131,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
// the document attributes.

let create_document_response = collection_client
.create_document(Context::new(), &doc, CreateDocumentOptions::new())
.create_document(&doc, CreateDocumentOptions::new())
.await?;
println!(
"create_document_response == {:#?}",
Expand All @@ -155,7 +155,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let get_document_response = collection_client
.clone()
.into_document_client(doc.id.clone(), &doc.id)?
.get_document::<MySampleStruct>(Context::new(), GetDocumentOptions::new())
.get_document::<MySampleStruct>(GetDocumentOptions::new())
.await?;
println!("get_document_response == {:#?}", get_document_response);

Expand Down Expand Up @@ -187,7 +187,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
.clone()
.into_database_client(DATABASE.to_owned())
.into_collection_client(COLLECTION.to_owned())
.delete_collection(Context::new(), DeleteCollectionOptions::new())
.delete_collection(DeleteCollectionOptions::new())
.await?;
println!("collection deleted");

Expand Down
12 changes: 3 additions & 9 deletions sdk/cosmos/examples/document_entries_00.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
// let's add an entity.
response = Some(
client
.create_document(Context::new(), &doc, CreateDocumentOptions::new())
.create_document(&doc, CreateDocumentOptions::new())
.await?,
);
}
Expand Down Expand Up @@ -128,10 +128,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let response = client
.clone()
.into_document_client(id.clone(), partition_key)?
.get_document::<MySampleStruct>(
Context::new(),
GetDocumentOptions::new().consistency_level(session_token),
)
.get_document::<MySampleStruct>(GetDocumentOptions::new().consistency_level(session_token))
.await?;

assert!(matches!(response, GetDocumentResponse::Found(_)));
Expand Down Expand Up @@ -166,10 +163,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let response = client
.clone()
.into_document_client(id.clone(), &id)?
.get_document::<MySampleStruct>(
Context::new(),
GetDocumentOptions::new().consistency_level(&response),
)
.get_document::<MySampleStruct>(GetDocumentOptions::new().consistency_level(&response))
.await?;

assert!(matches!(response, GetDocumentResponse::NotFound(_)));
Expand Down
9 changes: 1 addition & 8 deletions sdk/cosmos/examples/document_entries_01.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use azure_core::Context;
use azure_cosmos::prelude::*;
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
Expand Down Expand Up @@ -50,11 +49,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {

// let's add an entity.
let create_document_response = client
.create_document(
Context::new(),
&doc,
CreateDocumentOptions::new().is_upsert(true),
)
.create_document(&doc, CreateDocumentOptions::new().is_upsert(true))
.await?;

println!(
Expand All @@ -66,7 +61,6 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
.clone()
.into_document_client(doc.id.clone(), &doc.id)?
.get_document::<serde_json::Value>(
Context::new(),
GetDocumentOptions::new().consistency_level(&create_document_response),
)
.await?;
Expand All @@ -76,7 +70,6 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
.clone()
.into_document_client("ciccia", &doc.id)?
.get_document::<serde_json::Value>(
Context::new(),
GetDocumentOptions::new().consistency_level(&create_document_response),
)
.await?;
Expand Down
3 changes: 1 addition & 2 deletions sdk/cosmos/examples/get_database.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use azure_core::prelude::*;
use azure_cosmos::prelude::*;
use std::error::Error;

Expand All @@ -25,7 +24,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let database_client = client.into_database_client(database_name.clone());

let response = database_client
.get_database(Context::new(), GetDatabaseOptions::new())
.get_database(GetDatabaseOptions::new())
.await?;
println!("response == {:?}", response);

Expand Down
Loading