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

Commit

Permalink
Merge pull request #173 from zpgaal/gzp
Browse files Browse the repository at this point in the history
Some helper struct to wrap a TableService and a table name.
  • Loading branch information
MindFlavor authored Dec 1, 2019
2 parents 727bb69 + 717c3b9 commit 8b926c2
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions azure_sdk_storage_table/src/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use serde_json;

const TABLE_TABLES: &str = "TABLES";

#[derive(Clone)]
pub struct TableService {
client: Client,
}
Expand Down Expand Up @@ -331,6 +332,79 @@ impl TableService {
}
}

#[derive(Clone)]
pub struct TableStorage {
service: TableService,
table_name: String,
}

impl TableStorage {
pub fn new<S:Into<String>>(service: TableService, table_name: S) -> Self {
TableStorage {
service,
table_name: table_name.into()
}
}

pub fn create_table(&self) -> impl Future<Item = (), Error = AzureError> {
self.service.create_table(self.table_name.clone())
}

pub fn get_entity<T: DeserializeOwned>(
&self,
partition_key: &str,
row_key: &str,
) -> impl Future<Item = Option<T>, Error = AzureError> {
self.service.get_entity(&self.table_name, partition_key, row_key)
}

pub fn query_entities<T: DeserializeOwned>(
&self,
query: Option<&str>,
) -> impl Future<Item = Vec<T>, Error = AzureError> {
self.service.query_entities(&self.table_name, query)
}

pub fn stream_query_entities<'a, T: DeserializeOwned + 'a>(
&'a self,
query: Option<&'a str>,
) -> impl Stream<Item = T, Error = AzureError> + 'a {
self.service.stream_query_entities(&self.table_name, query)
}

pub fn stream_query_entities_fullmetadata<'a, T: DeserializeOwned + 'a>(
&'a self,
query: Option<&'a str>,
) -> impl Stream<Item = T, Error = AzureError> + 'a {
self.service.stream_query_entities_fullmetadata(&self.table_name, query)
}

pub fn insert_entity<T: Serialize>(&self, entity: &T) -> impl Future<Item = (), Error = AzureError> {
self.service.insert_entity::<T>(&self.table_name, entity)
}

pub fn update_entity<T: Serialize>(
&self,
partition_key: &str,
row_key: &str,
entity: &T,
) -> impl Future<Item = (), Error = AzureError> {
self.service.update_entity(&self.table_name, partition_key, row_key, entity)
}

pub fn delete_entity(&self, partition_key: &str, row_key: &str) -> impl Future<Item = (), Error = AzureError> {
self.service.delete_entity(&self.table_name, partition_key, row_key)
}

pub fn batch<T: Serialize>(
&self,
partition_key: &str,
batch_items: &[BatchItem<T>],
) -> impl Future<Item = (), Error = AzureError> {
self.service.batch(&self.table_name, partition_key, batch_items)
}
}

const HEADER_NEXTPARTITIONKEY: &'static str = "x-ms-continuation-NextPartitionKey";
const HEADER_NEXTROWKEY: &'static str = "x-ms-continuation-NextRowKey";

Expand Down

0 comments on commit 8b926c2

Please sign in to comment.