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

Commit 032ed23

Browse files
authored
Merge pull request #30 from MindFlavor/candidate
Removed Azure attributes from query_document_json returned JSON
2 parents 6b687a7 + ecf4452 commit 032ed23

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
## [0.4.5](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/0.4.5) (2017-07-22)
2+
3+
**Breaking changes:**
4+
5+
* Removed Azure attributes from returned JSON (field ```QueryDocumentResponse<String>.results```).
6+
7+
The removed attributes are in this slice (from [src/azure/cosmos/client.rs](src/azure/cosmos/client.rs)):
8+
9+
```rust
10+
const AZURE_KEYS: [&'static str; 5] = ["_attachments", "_etag", "_rid", "_self", "_ts"];
11+
```
12+
113
## [0.4.4](https://github.com/MindFlavor/AzureSDKForRust/releases/tag/0.4.4) (2017-07-20)
214

315
**Implemented features:**

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "azure_sdk_for_rust"
3-
version = "0.4.4"
3+
version = "0.4.5"
44
description = "Rust wrappers around Microsoft Azure REST APIs"
55
readme = "README.md"
66
authors = ["Francesco Cogno <francesco.cogno@outlook.com>", "Dong Liu <doliu@microsoft.com>"]

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
[![Crate](https://img.shields.io/crates/v/azure_sdk_for_rust.svg)](https://crates.io/crates/azure_sdk_for_rust) [![legal](https://img.shields.io/crates/l/azure_sdk_for_rust.svg)](LICENSE) [![cratedown](https://img.shields.io/crates/d/azure_sdk_for_rust.svg)](https://crates.io/crates/azure_sdk_for_rust) [![cratelastdown](https://img.shields.io/crates/dv/azure_sdk_for_rust.svg)](https://crates.io/crates/azure_sdk_for_rust)
66

7-
[![tag](https://img.shields.io/github/tag/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/tree/0.4.4)
8-
[![release](https://img.shields.io/github/release/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/tree/0.4.4)
9-
[![commitssince](https://img.shields.io/github/commits-since/mindflavor/AzureSDKForRust/0.4.4.svg)](https://img.shields.io/github/commits-since/mindflavor/AzureSDKForRust/0.4.4.svg)
7+
[![tag](https://img.shields.io/github/tag/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/tree/0.4.5)
8+
[![release](https://img.shields.io/github/release/mindflavor/AzureSDKForRust.svg)](https://github.com/MindFlavor/AzureSDKForRust/tree/0.4.5)
9+
[![commitssince](https://img.shields.io/github/commits-since/mindflavor/AzureSDKForRust/0.4.5.svg)](https://img.shields.io/github/commits-since/mindflavor/AzureSDKForRust/0.4.5.svg)
1010

1111
## Introduction
1212
Microsoft Azure expose its technologies via REST API. These APIs are easily consumable from any language (good) but are weakly typed. With this library and its related [crate](https://crates.io/crates/azure_sdk_for_rust/) you can exploit the power of Microsoft Azure from Rust in a idiomatic way.

examples/query_document00.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn code() -> Result<(), Box<Error>> {
8181
println!("\nAs entities:\n{:?}", ret);
8282

8383
for doc in ret.results.into_iter() {
84-
println!("{:?}", doc.result);
84+
println!("{:?}", doc);
8585
}
8686

8787
// test continuation token

src/azure/cosmos/client.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use std::str::{FromStr, from_utf8};
3030

3131
use serde::Serialize;
3232
use serde_json::Value;
33+
use serde_json::map::Map;
3334
use serde::de::DeserializeOwned;
3435

3536
use crypto::hmac::Hmac;
@@ -77,6 +78,9 @@ header! { (DocumentDBIsQuery, "x-ms-documentdb-isquery") => [bool] }
7778
header! { (DocumentDBQueryEnableCrossPartition,
7879
"x-ms-documentdb-query-enablecrosspartition") => [bool] }
7980

81+
const AZURE_KEYS: [&'static str; 5] = ["_attachments", "_etag", "_rid", "_self", "_ts"];
82+
83+
8084
#[derive(Clone, Copy)]
8185
pub enum ResourceType {
8286
Databases,
@@ -1028,21 +1032,38 @@ fn query_documents_extract_result_json(
10281032

10291033
let mut v_docs = Vec::new();
10301034

1031-
for doc in d.as_array().unwrap().iter() {
1035+
for doc in d.as_array().unwrap().into_iter() {
10321036
// We could either have a Document or a plain entry.
10331037
// We will find out here.
1034-
let doc_json = doc.to_string();
10351038

1036-
let document_attributes = match serde_json::from_str::<DocumentAttributes>(&doc_json) {
1039+
let document_attributes = match serde_json::from_value::<DocumentAttributes>(doc.clone()) {
10371040
Ok(document_attributes) => Some(document_attributes),
10381041
Err(_) => None,
10391042
};
10401043

10411044
debug!("\ndocument_attributes == {:?}", document_attributes);
10421045

1046+
// Now we are about to create a new Value::Object
1047+
// without the extra Azure fields.
1048+
// This involves a lot a copying (unfortunately).
1049+
let o_new = {
1050+
let mut o_new = Value::Object(Map::new());
1051+
{
1052+
let mut m_new = o_new.as_object_mut().unwrap();
1053+
1054+
for (key, val) in doc.as_object().unwrap() {
1055+
if AZURE_KEYS.binary_search(&(&key as &str)).is_err() {
1056+
m_new.insert(key.clone(), val.clone());
1057+
}
1058+
}
1059+
}
1060+
1061+
o_new
1062+
};
1063+
10431064
v_docs.push(QueryResult {
10441065
document_attributes: document_attributes,
1045-
result: doc_json,
1066+
result: o_new.to_string(),
10461067
});
10471068
}
10481069

0 commit comments

Comments
 (0)