Skip to content
This repository was archived by the owner on Oct 6, 2020. It is now read-only.

Commit 63aac16

Browse files
authored
Merge pull request #39 from nayato/api
pub mod reshuffling and extras...
2 parents bb6e312 + 6dc5056 commit 63aac16

24 files changed

+565
-312
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ log = "0.4.1"
2525
mime = "0.3.7"
2626
native-tls = "0.1.5"
2727
quick-error = "1.2.1"
28-
rust-crypto = "0.2.36"
2928
serde = "1.0.54"
3029
serde_derive = "1.0.54"
3130
serde_json = "1.0.17"
3231
time = "0.1.40"
33-
tokio-core = "0.1.17"
32+
tokio-core = "0.1.12"
3433
url = "1.7.0"
3534
uuid = "0.6.3"
35+
smallvec = { version = "0.6", features = ["serde"] }
3636

3737
[features]
3838
test_e2e = []

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,12 @@ use std::error::Error;
4141
use futures::future::*;
4242
use tokio_core::reactor::Core;
4343

44-
use azure_sdk_for_rust::azure::cosmos::authorization_token::{AuthorizationToken, TokenType};
45-
use azure_sdk_for_rust::azure::cosmos::client::Client;
46-
use azure_sdk_for_rust::azure::cosmos::partition_key::PartitionKey;
44+
use azure_sdk_for_rust::cosmos::{AuthorizationToken, TokenType, Client, PartitionKey};
4745

4846

4947
#[macro_use]
5048
extern crate serde_derive;
51-
use azure_sdk_for_rust::azure::cosmos;
49+
use azure_sdk_for_rust::cosmos;
5250

5351
#[derive(Serialize, Deserialize, Debug)]
5452
struct MySampleStruct<'a> {
@@ -165,12 +163,10 @@ fn code() -> Result<(), Box<Error>> {
165163
// Notice how easy it is! :)
166164
// The method create_document will return, upon success,
167165
// the document attributes.
168-
let document_attributes = core.run(client.create_document_as_entity(
166+
let document_attributes = core.run(client.create_document(
169167
&database,
170168
&collection,
171-
false,
172-
None,
173-
&PartitionKey::default(),
169+
&CreateDocumentOptions::default(),
174170
&doc,
175171
))?;
176172
println!("document_attributes == {:?}", document_attributes);

examples/blob00.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ use std::error::Error;
1313
use futures::future::*;
1414
use tokio_core::reactor::Core;
1515

16-
use azure_sdk_for_rust::azure::storage::blob::Blob;
17-
use azure_sdk_for_rust::azure::storage::client::Client;
16+
use azure_sdk_for_rust::storage::{
17+
blob::Blob,
18+
client::Client
19+
};
1820

1921
fn main() {
2022
env_logger::init();

examples/blob01.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ use std::error::Error;
1515
use futures::future::*;
1616
use tokio_core::reactor::Core;
1717

18-
use azure_sdk_for_rust::azure::core::lease::{LeaseState, LeaseStatus};
19-
use azure_sdk_for_rust::azure::storage::blob::{Blob, BlobType, PUT_OPTIONS_DEFAULT};
20-
use azure_sdk_for_rust::azure::storage::client::Client;
18+
use azure_sdk_for_rust::{
19+
core::lease::{LeaseState, LeaseStatus},
20+
storage::blob::{Blob, BlobType, PUT_OPTIONS_DEFAULT},
21+
storage::client::Client
22+
};
2123

2224
fn main() {
2325
env_logger::init();

examples/collection.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use std::error::Error;
1010
use futures::future::*;
1111
use tokio_core::reactor::Core;
1212

13-
use azure_sdk_for_rust::azure::cosmos::authorization_token::{AuthorizationToken, TokenType};
14-
use azure_sdk_for_rust::azure::cosmos::client::Client;
13+
use azure_sdk_for_rust::cosmos::{AuthorizationToken, TokenType, Client};
1514

1615

1716
fn main() {

examples/container00.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ use std::error::Error;
1010
use futures::future::*;
1111
use tokio_core::reactor::Core;
1212

13-
use azure_sdk_for_rust::azure::storage::client::Client;
14-
15-
use azure_sdk_for_rust::azure::storage::container::Container;
16-
use azure_sdk_for_rust::azure::storage::container::LIST_CONTAINER_OPTIONS_DEFAULT;
17-
18-
use azure_sdk_for_rust::azure::storage::blob::{Blob, LIST_BLOB_OPTIONS_DEFAULT};
13+
use azure_sdk_for_rust::storage::{
14+
client::Client,
15+
container::{Container, LIST_CONTAINER_OPTIONS_DEFAULT},
16+
blob::{Blob, LIST_BLOB_OPTIONS_DEFAULT}
17+
};
1918

2019
fn main() {
2120
code().unwrap();

examples/create_delete_database.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ use std::error::Error;
1010
use futures::future::*;
1111
use tokio_core::reactor::Core;
1212

13-
use azure_sdk_for_rust::azure::cosmos::authorization_token::{AuthorizationToken, TokenType};
14-
use azure_sdk_for_rust::azure::cosmos::client::Client;
13+
use azure_sdk_for_rust::cosmos::{AuthorizationToken, TokenType, Client};
1514

1615

1716
fn main() {

examples/document00.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,12 @@ use std::error::Error;
1111
use futures::future::*;
1212
use tokio_core::reactor::Core;
1313

14-
use azure_sdk_for_rust::azure::cosmos::authorization_token::{AuthorizationToken, TokenType};
15-
use azure_sdk_for_rust::azure::cosmos::client::Client;
16-
use azure_sdk_for_rust::azure::cosmos::partition_key::PartitionKey;
14+
use azure_sdk_for_rust::cosmos::{AuthorizationToken, TokenType, Client, CreateDocumentOptions};
1715

1816

1917
#[macro_use]
2018
extern crate serde_derive;
21-
use azure_sdk_for_rust::azure::cosmos;
19+
use azure_sdk_for_rust::cosmos;
2220

2321
#[derive(Serialize, Deserialize, Debug)]
2422
struct MySampleStruct<'a> {
@@ -135,12 +133,10 @@ fn code() -> Result<(), Box<Error>> {
135133
// Notice how easy it is! :)
136134
// The method create_document will return, upon success,
137135
// the document attributes.
138-
let document_attributes = core.run(client.create_document_as_entity(
136+
let document_attributes = core.run(client.create_document(
139137
&database.id,
140138
&collection.id,
141-
false,
142-
None,
143-
&PartitionKey::default(),
139+
&CreateDocumentOptions::default(),
144140
&doc,
145141
))?;
146142
println!("document_attributes == {:?}", document_attributes);

examples/document_entries00.rs

Lines changed: 99 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ use std::error::Error;
1010

1111
use tokio_core::reactor::Core;
1212

13-
use azure_sdk_for_rust::azure::cosmos::authorization_token::{AuthorizationToken, TokenType};
14-
use azure_sdk_for_rust::azure::cosmos::client::Client;
15-
use azure_sdk_for_rust::azure::cosmos::list_documents::LIST_DOCUMENTS_OPTIONS_DEFAULT;
16-
use azure_sdk_for_rust::azure::cosmos::partition_key::PartitionKey;
17-
use azure_sdk_for_rust::azure::cosmos::get_document::GetDocumentOptions;
18-
use azure_sdk_for_rust::azure::cosmos::request_response::{GetDocumentResponse,
19-
ListDocumentsResponse};
13+
use azure_sdk_for_rust::cosmos::{
14+
AuthorizationToken, TokenType, Client,
15+
PartitionKey, GetDocumentOptions, CreateDocumentOptions, ReplaceDocumentOptions, ListDocumentsOptions, DeleteDocumentOptions,
16+
request_response::{GetDocumentResponse, ListDocumentsResponse}
17+
};
2018

2119
#[macro_use]
2220
extern crate serde_derive;
@@ -83,96 +81,131 @@ fn code() -> Result<(), Box<Error>> {
8381

8482
// let's add an entity. we ignore the errors at this point and just
8583
// notify the user.
86-
match core.run(client.create_document_as_entity(
84+
core.run(client.create_document(
8785
&database_name,
8886
&collection_name,
89-
false,
90-
None,
91-
&partition_key,
87+
&CreateDocumentOptions { partition_key, ..Default::default() },
9288
&doc,
93-
)) {
94-
Ok(_) => {
95-
println!("entity added");
96-
}
97-
Err(error) => {
98-
println!("entity add failed (maybe already there?) {:?}", error);
99-
}
100-
};
89+
)).expect("entity creation failed");
10190
}
91+
// core.run(
92+
// futures::future::join_all((0..5).map(|i| {
93+
// let doc = MySampleStruct {
94+
// id: &format!("unique_id{}", i),
95+
// a_string: "Something here",
96+
// a_number: i,
97+
// a_timestamp: chrono::Utc::now().timestamp(),
98+
// };
99+
100+
// let mut cdo = CreateDocumentOptions::default();
101+
// cdo.partition_key.push(doc.id);
102+
103+
// // let's add an entity. we ignore the errors at this point and just
104+
// // notify the user.
105+
// client.create_document(
106+
// &database_name,
107+
// &collection_name,
108+
// &cdo,
109+
// &doc
110+
// )
111+
// }))
112+
// ).unwrap();
113+
println!("Created 5 documents.");
102114

103115
// let's get 3 entries at a time
104-
let mut ldo = LIST_DOCUMENTS_OPTIONS_DEFAULT.clone();
105-
ldo.max_item_count = Some(3);
106-
107116
let response: ListDocumentsResponse<MySampleStructOwned> = core.run(client.list_documents(
108117
&database_name,
109118
&collection_name,
110-
&ldo,
119+
&ListDocumentsOptions { max_item_count: Some(3), ..Default::default() },
111120
)).unwrap();
112121

113122
assert_eq!(response.documents.len(), 3);
114-
println!("response == {:?}", response);
123+
println!("response == {:#?}", response);
115124

116125
// we inserted 5 documents and retrieved the first 3.
117126
// continuation_token must be present
118127
assert_eq!(
119128
response.additional_headers.continuation_token.is_some(),
120129
true
121130
);
122-
if let Some(ct) = response.additional_headers.continuation_token {
123-
println!("ct == {}", ct);
131+
132+
let ct = response.additional_headers.continuation_token.unwrap();
133+
println!("ct == {}", ct);
124134

125-
let mut ldo = LIST_DOCUMENTS_OPTIONS_DEFAULT.clone();
126-
ldo.continuation_token = Some(&ct);
135+
let response: ListDocumentsResponse<MySampleStructOwned> = core.run(client.list_documents(
136+
&database_name,
137+
&collection_name,
138+
&ListDocumentsOptions { continuation_token: Some(&ct), ..Default::default() },
139+
)).unwrap();
127140

128-
let response: ListDocumentsResponse<MySampleStructOwned> = core.run(client.list_documents(
129-
&database_name,
130-
&collection_name,
131-
&ldo,
132-
)).unwrap();
141+
assert_eq!(response.documents.len(), 2);
142+
println!("response == {:#?}", response);
133143

134-
assert_eq!(response.documents.len(), 47);
135-
println!("response == {:?}", response);
144+
// we got the last 2 entries. Now continuation_token
145+
// must be absent
146+
assert_eq!(
147+
response.additional_headers.continuation_token.is_some(),
148+
false
149+
);
136150

137-
// we got the last 47 entries. Now continuation_token
138-
// must be absent
139-
assert_eq!(
140-
response.additional_headers.continuation_token.is_some(),
141-
false
142-
);
151+
println!("\n\nLooking for a specific item");
152+
let id = format!("unique_id{}", 3);
153+
let mut gdo = GetDocumentOptions::default();
154+
gdo.partition_key.push(&id);
143155

156+
let response: GetDocumentResponse<MySampleStructOwned> = core.run(client.get_document(
157+
&database_name,
158+
&collection_name,
159+
&id,
160+
&gdo,
161+
)).unwrap();
144162

145-
println!("\n\nLooking for a specific item");
146-
let id = format!("unique_id{}", 3);
147-
let mut gdo = GetDocumentOptions::default();
148-
gdo.partition_key.push(&id);
163+
assert_eq!(response.document.is_some(), true);
164+
println!("response == {:#?}", response);
165+
let mut doc = response.document.unwrap();
166+
doc.entity.a_string = "Something else here".into();
167+
let mut rdo = ReplaceDocumentOptions::default();
168+
rdo.if_match = Some(&doc.document_attributes.etag); // use optimistic concurrency check
169+
rdo.partition_key.push(&id);
149170

150-
let response: GetDocumentResponse<MySampleStructOwned> = core.run(client.get_document(
151-
&database_name,
152-
&collection_name,
153-
&id,
154-
&gdo,
155-
)).unwrap();
171+
let _response = core.run(client.replace_document(
172+
&database_name,
173+
&collection_name,
174+
&rdo,
175+
&doc
176+
)).unwrap();
156177

157-
assert_eq!(response.document.is_some(), true);
158-
println!("response == {:?}", response);
178+
// This id should not be found. We expect None as result
179+
println!("\n\nLooking for non-existing item");
180+
let id = format!("unique_id{}", 100);
181+
let mut gdo = GetDocumentOptions::default();
182+
gdo.partition_key.push(&id);
159183

160-
// This id should not be found. We expect None as result
161-
println!("\n\nLooking for non-existing item");
162-
let id = format!("unique_id{}", 100);
163-
let mut gdo = GetDocumentOptions::default();
164-
gdo.partition_key.push(&id);
184+
let response: GetDocumentResponse<MySampleStructOwned> = core.run(client.get_document(
185+
&database_name,
186+
&collection_name,
187+
&id,
188+
&gdo,
189+
)).unwrap();
165190

166-
let response: GetDocumentResponse<MySampleStructOwned> = core.run(client.get_document(
167-
&database_name,
168-
&collection_name,
169-
&id,
170-
&gdo,
171-
)).unwrap();
191+
assert_eq!(response.document.is_some(), false);
192+
println!("response == {:#?}", response);
172193

173-
assert_eq!(response.document.is_some(), false);
174-
println!("response == {:?}", response);
194+
for i in 0..5 {
195+
let id = format!("unique_id{}", i);
196+
let mut ddo = DeleteDocumentOptions::default();
197+
ddo.partition_key.push(&id);
198+
core.run(
199+
client.delete_document(
200+
&database_name,
201+
&collection_name,
202+
&id,
203+
&ddo
204+
)
205+
).unwrap();
175206
}
176207

208+
println!("Cleaned up");
209+
177210
Ok(())
178211
}

examples/lease_blob.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ use std::error::Error;
1212
use futures::future::*;
1313
use tokio_core::reactor::Core;
1414

15-
use azure_sdk_for_rust::azure::core::lease::{LeaseAction, LeaseState, LeaseStatus};
16-
use azure_sdk_for_rust::azure::storage::blob::{Blob, BlobType, LEASE_BLOB_OPTIONS_DEFAULT};
17-
use azure_sdk_for_rust::azure::storage::client::Client;
15+
use azure_sdk_for_rust::{
16+
core::lease::{LeaseAction, LeaseState, LeaseStatus},
17+
storage::blob::{Blob, BlobType, LEASE_BLOB_OPTIONS_DEFAULT},
18+
storage::client::Client
19+
};
1820

1921
use hyper::mime::Mime;
2022

0 commit comments

Comments
 (0)