@@ -13,7 +13,7 @@ Crate | Docs | Crates.io | Downloads | Downloads@Latest |
13
13
-- | -- | -- | -- | -- |
14
14
[ 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 )
15
15
[ 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 )
17
17
[ 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 )
18
18
[ 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 )
19
19
[ 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
42
42
``` rust
43
43
#[macro_use]
44
44
extern 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
46
46
// DB.
47
47
use azure_sdk_core :: prelude :: * ;
48
48
use azure_sdk_cosmos :: prelude :: * ;
@@ -55,6 +55,7 @@ use std::error::Error;
55
55
// work (you can create with this SDK too, check the examples folder for that task).
56
56
#[derive(Serialize , Deserialize , Debug )]
57
57
struct MySampleStruct <'a > {
58
+ id : Cow <'a , str >,
58
59
a_string : Cow <'a , str >,
59
60
a_number : u64 ,
60
61
a_timestamp : i64 ,
@@ -98,14 +99,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
98
99
println! (" Inserting 10 documents..." );
99
100
for i in 0 .. 10 {
100
101
// 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
+ });
109
108
110
109
// insert it!
111
110
collection_client
@@ -138,10 +137,12 @@ async fn main() -> Result<(), Box<dyn Error>> {
138
137
println! (" \ n Querying documents" );
139
138
let query_documents_response = collection_client
140
139
. 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.
142
141
. 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
145
146
146
147
println! (
147
148
" Received {} documents!" ,
@@ -151,19 +152,22 @@ async fn main() -> Result<(), Box<dyn Error>> {
151
152
query_documents_response
152
153
. results
153
154
. iter ()
154
- . for_each (| document | println! (" number ==> {}" , document . result. a_number));
155
+ . for_each (| document | {
156
+ println! (" number ==> {}" , document . result. a_number);
157
+ });
155
158
156
159
// TASK 4
157
160
for ref document in query_documents_response . results {
161
+ // From our query above we are sure to receive a Document.
158
162
println! (
159
163
" deleting id == {}, a_number == {}." ,
160
- document . document_attributes . id, document . result. a_number
164
+ document . result . id, document . result. a_number
161
165
);
162
166
163
167
// to spice the delete a little we use optimistic concurreny
164
168
collection_client
165
169
. with_document (
166
- & document . document_attributes . id,
170
+ & document . result . id,
167
171
PartitionKeys :: new (). push (& document . result. a_number)? ,
168
172
)
169
173
. delete_document ()
0 commit comments