Skip to content

Create azure_data_tables crate from azure_storage #546

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

Merged
merged 3 commits into from
Dec 20, 2021
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ jobs:

- name: e2e tests build
run: |
PROJECTS=(core cosmos identity messaging_servicebus storage storage_blobs storage_queues)
PROJECTS=(core cosmos identity messaging_servicebus storage storage_blobs storage_queues data_tables)
for PROJ in ${PROJECTS[@]}
do
echo "Checking e2e tests for $PROJ"
Expand Down
35 changes: 35 additions & 0 deletions sdk/data_tables/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "azure_data_tables"
version = "0.1.0"
description = "Rust wrappers around Microsoft Azure Data Tables REST APIs"
readme = "README.md"
authors = ["Microsoft Corp."]
license = "MIT"
repository = "https://github.com/azure/azure-sdk-for-rust"
homepage = "https://github.com/azure/azure-sdk-for-rust"
documentation = "https://docs.rs/azure_data_tables"
keywords = ["sdk", "azure", "rest", "iot", "cloud", "data", "tables"]
categories = ["api-bindings"]
edition = "2018"

[dependencies]
azure_core = { path = "../core", version = "0.1.0" }
azure_storage = { path = "../storage", version = "0.1.0" }
bytes = "1.0"
chrono = { version = "0.4", features = ["serde"] }
futures = "0.3"
http = "0.2"
log = "0.4"
once_cell = "1.0"
serde = { version = "1.0" }
serde_derive = "1.0"
serde_json = "1.0"
serde-xml-rs = "0.4"
uuid = { version = "0.8", features = ["v4"] }
url = "2.2"

[dev-dependencies]
tokio = { version = "1.0", features = ["full"] }

[features]
test_e2e = []
12 changes: 12 additions & 0 deletions sdk/data_tables/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Azure SDK for Rust - Azure Data Tables

Azure Data Tables crate for the unofficial Microsoft Azure SDK for Rust. This crate is part of a collection of crates: for more information please refer to [https://github.com/azure/azure-sdk-for-rust](https://github.com/azure/azure-sdk-for-rust).

## Usage

To set this crate as a dependency, add this to your Cargo.toml

```toml
[dependencies]
azure_data_tables = { version = "0.1.0", git = "https://github.com/Azure/azure-sdk-for-rust" }
```
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use azure_data_tables::prelude::*;
use azure_storage::core::prelude::*;
use azure_storage::table::prelude::*;
use futures::stream::StreamExt;
use serde::{Deserialize, Serialize};
use std::error::Error;
Expand Down Expand Up @@ -34,8 +34,8 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
.as_storage_client()
.as_table_service_client()?;

let table = table_service.as_table_client(table_name);
let response = table.create().execute().await?;
let table_client = table_service.as_table_client(table_name);
let response = table_client.create().execute().await?;
println!("response = {:?}\n", response);

let mut entity = MyEntity {
Expand All @@ -44,17 +44,17 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
surname: "Cogno".to_owned(),
};

let partition_key_client = table.as_partition_key_client(&entity.city);
let partition_key_client = table_client.as_partition_key_client(&entity.city);

let mut transaction = Transaction::default();

transaction.add(table.insert().to_transaction_operation(&entity)?);
transaction.add(table_client.insert().to_transaction_operation(&entity)?);

entity.surname = "Doe".to_owned();
transaction.add(table.insert().to_transaction_operation(&entity)?);
transaction.add(table_client.insert().to_transaction_operation(&entity)?);

entity.surname = "Karl".to_owned();
transaction.add(table.insert().to_transaction_operation(&entity)?);
transaction.add(table_client.insert().to_transaction_operation(&entity)?);

entity.surname = "Potter".to_owned();
let entity_client = partition_key_client.as_entity_client(&entity.surname)?;
Expand All @@ -73,7 +73,11 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let response = entity_client.delete().execute().await?;
println!("response = {:?}\n", response);

let response = table.insert().return_entity(false).execute(&entity).await?;
let response = table_client
.insert()
.return_entity(false)
.execute(&entity)
.await?;
println!("response = {:?}\n", response);

// Get an entity from the table
Expand All @@ -83,10 +87,14 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let mut entity: MyEntity = response.entity;
entity.city = "Rome".to_owned();

let response = table.insert().return_entity(true).execute(&entity).await?;
let response = table_client
.insert()
.return_entity(true)
.execute(&entity)
.await?;
println!("response = {:?}\n", response);

let entity_client = table
let entity_client = table_client
.as_partition_key_client(&entity.city)
.as_entity_client(&entity.surname)?;
// update the name passing the Etag received from the previous call.
Expand All @@ -108,7 +116,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
}

let mut stream = Box::pin(
table
table_client
.query()
.filter("Name = 'Carl'")
.top(2)
Expand All @@ -118,7 +126,7 @@ async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
println!("response = {:?}\n", response);
}

let response = table.delete().execute().await?;
let response = table_client.delete().execute().await?;
println!("response = {:?}\n", response);

Ok(())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::table::prelude::*;
use crate::table::requests::*;
use crate::prelude::*;
use crate::requests::*;
use bytes::Bytes;
use http::method::Method;
use http::request::{Builder, Request};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::core::clients::StorageAccountClient;
use crate::table::prelude::*;
use crate::table::requests::*;
use crate::prelude::*;
use crate::requests::*;
use azure_storage::core::clients::StorageAccountClient;
use bytes::Bytes;
use http::method::Method;
use http::request::{Builder, Request};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::core::clients::StorageAccountClient;
use crate::table::clients::TableServiceClient;
use crate::table::requests::*;
use crate::clients::TableServiceClient;
use crate::requests::*;
use azure_storage::core::clients::StorageAccountClient;
use bytes::Bytes;
use http::method::Method;
use http::request::{Builder, Request};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::core::clients::{StorageAccountClient, StorageClient};
use crate::table::requests::ListTablesBuilder;
use crate::requests::ListTablesBuilder;
use azure_storage::core::clients::{StorageAccountClient, StorageClient};
use bytes::Bytes;
use http::method::Method;
use http::request::{Builder, Request};
Expand Down Expand Up @@ -67,7 +67,7 @@ impl TableServiceClient {
url,
method,
http_header_adder,
crate::core::clients::ServiceType::Table,
azure_storage::core::clients::ServiceType::Table,
request_body,
)
}
Expand Down
File renamed without changes.
9 changes: 9 additions & 0 deletions sdk/storage/src/table/mod.rs → sdk/data_tables/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
#[macro_use]
extern crate log;
#[macro_use]
extern crate serde_derive;
#[macro_use]
extern crate azure_core;

pub use azure_storage::{Error, Result};

pub mod clients;
mod continuation_next_partition_and_row_key;
mod continuation_next_table_name;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub use crate::table::clients::{
pub use crate::clients::{
AsEntityClient, AsPartitionKeyClient, AsTableClient, AsTableServiceClient, EntityClient,
PartitionKeyClient, TableClient, TableServiceClient,
};
pub use crate::table::{Filter, IfMatchCondition, ReturnEntity, Select, Table, Top, Transaction};
pub use crate::{Filter, IfMatchCondition, ReturnEntity, Select, Table, Top, Transaction};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::table::prelude::*;
use crate::table::responses::*;
use crate::prelude::*;
use crate::responses::*;
use azure_core::headers::add_optional_header;
use azure_core::prelude::*;
use http::method::Method;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::table::prelude::IfMatchCondition;
use crate::table::prelude::*;
use crate::table::responses::*;
use crate::table::TransactionOperation;
use crate::prelude::IfMatchCondition;
use crate::prelude::*;
use crate::responses::*;
use crate::TransactionOperation;
use azure_core::headers::{add_mandatory_header, add_optional_header};
use azure_core::prelude::*;
use http::{method::Method, StatusCode};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::table::prelude::*;
use crate::table::responses::*;
use crate::prelude::*;
use crate::responses::*;
use azure_core::headers::add_optional_header;
use azure_core::prelude::*;
use http::method::Method;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::table::prelude::*;
use crate::table::responses::*;
use crate::prelude::*;
use crate::responses::*;
use azure_core::prelude::*;
use azure_core::{headers::add_optional_header, AppendToUrlQuery};
use http::method::Method;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::table::prelude::*;
use crate::table::responses::*;
use crate::table::TransactionOperation;
use crate::prelude::*;
use crate::responses::*;
use crate::TransactionOperation;
use azure_core::headers::{add_mandatory_header, add_optional_header};
use azure_core::prelude::*;
use http::method::Method;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::table::prelude::*;
use crate::table::responses::*;
use crate::table::TransactionOperation;
use crate::prelude::*;
use crate::responses::*;
use crate::TransactionOperation;
use azure_core::headers::add_optional_header;
use azure_core::prelude::*;
use http::{method::Method, StatusCode};
Expand Down Expand Up @@ -54,7 +54,7 @@ impl<'a> InsertOrReplaceOrMergeEntityBuilder<'a> {
let request = self.entity_client.prepare_request(
url.as_str(),
match self.operation {
Operation::InsertOrMerge => &crate::table::MERGE,
Operation::InsertOrMerge => &crate::MERGE,
Operation::InsertOrReplace => &Method::PUT,
},
&|mut request| {
Expand Down Expand Up @@ -87,7 +87,7 @@ impl<'a> InsertOrReplaceOrMergeEntityBuilder<'a> {

let request = http::Request::builder()
.method(match self.operation {
Operation::InsertOrMerge => &crate::table::MERGE,
Operation::InsertOrMerge => &crate::MERGE,
Operation::InsertOrReplace => &Method::PUT,
})
.uri(url.as_str());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::table::responses::*;
use crate::{table::prelude::*, ContinuationNextTableName};
use crate::responses::*;
use crate::{prelude::*, ContinuationNextTableName};
use azure_core::prelude::*;
use azure_core::{headers::add_optional_header, AppendToUrlQuery};
use futures::stream::{unfold, Stream};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::table::responses::*;
use crate::{table::prelude::*, ContinuationNextPartitionAndRowKey};
use crate::responses::*;
use crate::{prelude::*, ContinuationNextPartitionAndRowKey};
use azure_core::prelude::*;
use azure_core::{headers::add_optional_header, AppendToUrlQuery};
use futures::stream::{unfold, Stream};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::table::prelude::*;
use crate::table::responses::*;
use crate::prelude::*;
use crate::responses::*;
use azure_core::headers::add_optional_header;
use azure_core::prelude::*;
use http::{method::Method, StatusCode};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::table::prelude::*;
use crate::table::responses::*;
use crate::table::IfMatchCondition;
use crate::table::TransactionOperation;
use crate::prelude::*;
use crate::responses::*;
use crate::IfMatchCondition;
use crate::TransactionOperation;
use azure_core::headers::{add_mandatory_header, add_optional_header};
use azure_core::prelude::*;
use http::{method::Method, StatusCode};
Expand Down Expand Up @@ -55,7 +55,7 @@ impl<'a> UpdateOrMergeEntityBuilder<'a> {
let request = self.entity_client.prepare_request(
url.as_str(),
match self.operation {
Operation::Merge => &crate::table::MERGE,
Operation::Merge => &crate::MERGE,
Operation::Update => &Method::PUT,
},
&|mut request| {
Expand Down Expand Up @@ -90,7 +90,7 @@ impl<'a> UpdateOrMergeEntityBuilder<'a> {

let request = http::Request::builder()
.method(match self.operation {
Operation::Merge => &crate::table::MERGE,
Operation::Merge => &crate::MERGE,
Operation::Update => &Method::PUT,
})
.uri(url.as_str());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::core::headers::CommonStorageResponseHeaders;
use crate::table::prelude::*;
use crate::prelude::*;
use azure_storage::core::headers::CommonStorageResponseHeaders;
use bytes::Bytes;
use http::Response;
use std::convert::{TryFrom, TryInto};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::core::headers::CommonStorageResponseHeaders;
use azure_storage::core::headers::CommonStorageResponseHeaders;
use bytes::Bytes;
use http::Response;
use std::convert::{TryFrom, TryInto};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::core::headers::CommonStorageResponseHeaders;
use azure_storage::core::headers::CommonStorageResponseHeaders;
use bytes::Bytes;
use http::Response;
use std::convert::{TryFrom, TryInto};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::core::headers::CommonStorageResponseHeaders;
use azure_storage::core::headers::CommonStorageResponseHeaders;
use bytes::Bytes;
use http::Response;
use serde::de::DeserializeOwned;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::core::headers::CommonStorageResponseHeaders;
use crate::core::util::HeaderMapExt;
use crate::EntityWithMetadata;
use azure_core::{
headers::{etag_from_headers, get_str_from_headers},
Etag,
};
use azure_storage::core::headers::CommonStorageResponseHeaders;
use azure_storage::core::util::HeaderMapExt;
use bytes::Bytes;
use http::Response;
use serde::de::DeserializeOwned;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::core::headers::CommonStorageResponseHeaders;
use crate::{table::prelude::*, ContinuationNextTableName};
use crate::{prelude::*, ContinuationNextTableName};
use azure_storage::core::headers::CommonStorageResponseHeaders;
use bytes::Bytes;
use http::Response;
use std::convert::{TryFrom, TryInto};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::core::headers::CommonStorageResponseHeaders;
use azure_core::{headers::etag_from_headers, Etag};
use azure_storage::core::headers::CommonStorageResponseHeaders;
use bytes::Bytes;
use http::Response;
use std::convert::{TryFrom, TryInto};
Expand Down
Loading