@@ -13,7 +13,7 @@ Crate | Docs | Crates.io | Downloads | Downloads@Latest |
1313-- | -- | -- | -- | -- |
1414[ azure_sdk_auth_aad] ( https://github.com/MindFlavor/AzureSDKForRust/tree/master/azure_sdk_auth_aad ) | [ ![ docs] ( https://docs.rs/azure_sdk_auth_aad/badge.svg )] ( https://docs.rs/azure_sdk_auth_aad/0.42.2/azure_sdk_auth_aad ) | [ ![ Crate] ( https://img.shields.io/crates/v/azure_sdk_auth_aad.svg )] ( https://crates.io/crates/azure_sdk_auth_aad ) | [ ![ cratedown] ( https://img.shields.io/crates/d/azure_sdk_auth_aad.svg )] ( https://crates.io/crates/azure_sdk_auth_aad ) | [ ![ cratelastdown] ( https://img.shields.io/crates/dv/azure_sdk_auth_aad.svg )] ( https://crates.io/crates/azure_sdk_auth_aad )
1515[ azure_sdk_core] ( https://github.com/MindFlavor/AzureSDKForRust/tree/master/azure_sdk_core ) | [ ![ docs] ( https://docs.rs/azure_sdk_core/badge.svg )] ( https://docs.rs/azure_sdk_core/0.43.2/azure_sdk_core ) | [ ![ Crate] ( https://img.shields.io/crates/v/azure_sdk_core.svg )] ( https://crates.io/crates/azure_sdk_core ) | [ ![ cratedown] ( https://img.shields.io/crates/d/azure_sdk_core.svg )] ( https://crates.io/crates/azure_sdk_core ) | [ ![ cratelastdown] ( https://img.shields.io/crates/dv/azure_sdk_core.svg )] ( https://crates.io/crates/azure_sdk_core )
16- [ azure_sdk_cosmos] ( https://github.com/MindFlavor/AzureSDKForRust/tree/master/azure_sdk_cosmos ) | [ ![ docs] ( https://docs.rs/azure_sdk_cosmos/badge.svg )] ( https://docs.rs/azure_sdk_cosmos/0.42.4 /azure_sdk_cosmos ) | [ ![ Crate] ( https://img.shields.io/crates/v/azure_sdk_cosmos.svg )] ( https://crates.io/crates/azure_sdk_cosmos ) | [ ![ cratedown] ( https://img.shields.io/crates/d/azure_sdk_cosmos.svg )] ( https://crates.io/crates/azure_sdk_cosmos ) | [ ![ cratelastdown] ( https://img.shields.io/crates/dv/azure_sdk_cosmos.svg )] ( https://crates.io/crates/azure_sdk_cosmos )
16+ [ azure_sdk_cosmos] ( https://github.com/MindFlavor/AzureSDKForRust/tree/master/azure_sdk_cosmos ) | [ ![ docs] ( https://docs.rs/azure_sdk_cosmos/badge.svg )] ( https://docs.rs/azure_sdk_cosmos/0.43.0 /azure_sdk_cosmos ) | [ ![ Crate] ( https://img.shields.io/crates/v/azure_sdk_cosmos.svg )] ( https://crates.io/crates/azure_sdk_cosmos ) | [ ![ cratedown] ( https://img.shields.io/crates/d/azure_sdk_cosmos.svg )] ( https://crates.io/crates/azure_sdk_cosmos ) | [ ![ cratelastdown] ( https://img.shields.io/crates/dv/azure_sdk_cosmos.svg )] ( https://crates.io/crates/azure_sdk_cosmos )
1717[ azure_sdk_service_bus] ( https://github.com/MindFlavor/AzureSDKForRust/tree/master/azure_sdk_service_bus ) | [ ![ docs] ( https://docs.rs/azure_sdk_service_bus/badge.svg )] ( https://docs.rs/azure_sdk_service_bus/0.44.0/azure_sdk_service_bus ) | [ ![ Crate] ( https://img.shields.io/crates/v/azure_sdk_service_bus.svg )] ( https://crates.io/crates/azure_sdk_service_bus ) | [ ![ cratedown] ( https://img.shields.io/crates/d/azure_sdk_service_bus.svg )] ( https://crates.io/crates/azure_sdk_service_bus ) | [ ![ cratelastdown] ( https://img.shields.io/crates/dv/azure_sdk_service_bus.svg )] ( https://crates.io/crates/azure_sdk_service_bus )
1818[ azure_sdk_storage_account] ( https://github.com/MindFlavor/AzureSDKForRust/tree/master/azure_sdk_storage_account ) | [ ![ docs] ( https://docs.rs/azure_sdk_storage_account/badge.svg )] ( https://docs.rs/azure_sdk_storage_account/0.40.4/azure_sdk_storage_account ) | [ ![ Crate] ( https://img.shields.io/crates/v/azure_sdk_storage_account.svg )] ( https://crates.io/crates/azure_sdk_storage_account ) | [ ![ cratedown] ( https://img.shields.io/crates/d/azure_sdk_storage_account.svg )] ( https://crates.io/crates/azure_sdk_storage_account ) | [ ![ cratelastdown] ( https://img.shields.io/crates/dv/azure_sdk_storage_account.svg )] ( https://crates.io/crates/azure_sdk_storage_account )
1919[ azure_sdk_storage_blob] ( https://github.com/MindFlavor/AzureSDKForRust/tree/master/azure_sdk_storage_blob ) | [ ![ docs] ( https://docs.rs/azure_sdk_storage_blob/badge.svg )] ( https://docs.rs/azure_sdk_storage_blob/0.43.2/azure_sdk_storage_blob ) | [ ![ Crate] ( https://img.shields.io/crates/v/azure_sdk_storage_blob.svg )] ( https://crates.io/crates/azure_sdk_storage_blob ) | [ ![ cratedown] ( https://img.shields.io/crates/d/azure_sdk_storage_blob.svg )] ( https://crates.io/crates/azure_sdk_storage_blob ) | [ ![ cratelastdown] ( https://img.shields.io/crates/dv/azure_sdk_storage_blob.svg )] ( https://crates.io/crates/azure_sdk_storage_blob )
@@ -42,7 +42,7 @@ You can find examples in the [```examples```](https://github.com/MindFlavor/Azur
4242``` rust
4343#[macro_use]
4444extern crate serde_derive;
45- // Using the prelude module of the Cosmos crate makes easier to use the Rust Azure SDK for Cosmos
45+ // Using the prelude module of the CosmosDB crate makes easier to use the Rust Azure SDK for Cosmos
4646// DB.
4747use azure_sdk_core :: prelude :: * ;
4848use azure_sdk_cosmos :: prelude :: * ;
@@ -55,6 +55,7 @@ use std::error::Error;
5555// work (you can create with this SDK too, check the examples folder for that task).
5656#[derive(Serialize , Deserialize , Debug )]
5757struct MySampleStruct <'a > {
58+ id : Cow <'a , str >,
5859 a_string : Cow <'a , str >,
5960 a_number : u64 ,
6061 a_timestamp : i64 ,
@@ -98,14 +99,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
9899 println! (" Inserting 10 documents..." );
99100 for i in 0 .. 10 {
100101 // define the document.
101- let document_to_insert = Document :: new (
102- format! (" unique_id{}" , i ), // this is the primary key, AKA "/id".
103- MySampleStruct {
104- a_string : Cow :: Borrowed (" Something here" ),
105- a_number : i * 100 , // this is the partition key
106- a_timestamp : chrono :: Utc :: now (). timestamp (),
107- },
108- );
102+ let document_to_insert = Document :: new (MySampleStruct {
103+ id : Cow :: Owned (format! (" unique_id{}" , i )),
104+ a_string : Cow :: Borrowed (" Something here" ),
105+ a_number : i * 100 , // this is the partition key
106+ a_timestamp : chrono :: Utc :: now (). timestamp (),
107+ });
109108
110109 // insert it!
111110 collection_client
@@ -138,10 +137,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
138137 println! (" \ n Querying documents" );
139138 let query_documents_response = collection_client
140139 . query_documents ()
141- . with_query (& (" SELECT * FROM A WHERE A.a_number < 600" . into ()))
140+ . with_query (& (" SELECT * FROM A WHERE A.a_number < 600" . into ())) // there are other ways to construct a query, this is the simplest.
142141 . with_query_cross_partition (true ) // this will perform a cross partition query! notice how simple it is!
143- . execute :: <MySampleStruct >()
144- . await ? ;
142+ . execute :: <MySampleStruct >() // This will make sure the result is our custom struct!
143+ . await ?
144+ . into_documents () // queries can return Documents or Raw json (ie without etag, _rid, etc...). Since our query return docs we convert with this function.
145+ . unwrap (); // we know in advance that the conversion to Document will not fail since we SELECT'ed * FROM table
145146
146147 println! (
147148 " Received {} documents!" ,
@@ -151,19 +152,22 @@ async fn main() -> Result<(), Box<dyn Error>> {
151152 query_documents_response
152153 . results
153154 . iter ()
154- . for_each (| document | println! (" number ==> {}" , document . result. a_number));
155+ . for_each (| document | {
156+ println! (" number ==> {}" , document . result. a_number);
157+ });
155158
156159 // TASK 4
157160 for ref document in query_documents_response . results {
161+ // From our query above we are sure to receive a Document.
158162 println! (
159163 " deleting id == {}, a_number == {}." ,
160- document . document_attributes . id, document . result. a_number
164+ document . result . id, document . result. a_number
161165 );
162166
163167 // to spice the delete a little we use optimistic concurreny
164168 collection_client
165169 . with_document (
166- & document . document_attributes . id,
170+ & document . result . id,
167171 PartitionKeys :: new (). push (& document . result. a_number)? ,
168172 )
169173 . delete_document ()
0 commit comments