#sdk #azure #storage #data-tables

azure_data_tables

Azure Table storage crate from the Azure SDK for Rust

14 breaking releases

0.15.0 Sep 8, 2023
0.13.0 Jun 28, 2023
0.11.0 Mar 17, 2023
0.9.0 Dec 16, 2022
0.1.0 Jan 25, 2022

#2 in #azure-storage

Download history 49/week @ 2023-06-06 57/week @ 2023-06-13 83/week @ 2023-06-20 39/week @ 2023-06-27 91/week @ 2023-07-04 21/week @ 2023-07-11 120/week @ 2023-07-18 42/week @ 2023-07-25 16/week @ 2023-08-01 37/week @ 2023-08-08 38/week @ 2023-08-15 66/week @ 2023-08-22 115/week @ 2023-08-29 70/week @ 2023-09-05 16/week @ 2023-09-12 75/week @ 2023-09-19

289 downloads per month

MIT license

345KB
8K SLoC

azure_data_tables

This crate is from the Azure SDK for Rust. It supports Azure Table storage.

use azure_core::StatusCode;
use azure_data_tables::{operations::InsertEntityResponse, prelude::*};
use azure_storage::prelude::*;
use futures::stream::StreamExt;
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
struct MyEntity {
    #[serde(rename = "PartitionKey")]
    pub city: String,
    pub name: String,
    #[serde(rename = "RowKey")]
    pub surname: String,
}

#[tokio::main]
async fn main() -> azure_core::Result<()> {
    env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"));

    // First we retrieve the account name and access key from environment variables.
    let account =
        std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!");
    let access_key =
        std::env::var("STORAGE_ACCESS_KEY").expect("Set env variable STORAGE_ACCESS_KEY first!");
    let table_name = std::env::var("STORAGE_TABLE_NAME").expect("Set env variable STORAGE_TABLE_NAME first!");

    let storage_credentials = StorageCredentials::Key(account.clone(), access_key);
    let table_service = TableServiceClient::new(account, storage_credentials);

    let table_client = table_service.table_client(table_name);
    table_client.create().await?;

    let entity = MyEntity {
        city: "Milan".to_owned(),
        name: "Francesco".to_owned(),
        surname: "A".to_owned(),
    };

    let _: InsertEntityResponse<MyEntity> = table_client.insert(&entity)?.await?;

    // Get a client that refers to the above entity
    let entity_client = table_client.partition_key_client(&entity.city).entity_client(&entity.surname)?;

    // Get an entity from the table
    let response = entity_client.get().await?;
    let mut entity: MyEntity = response.entity;

    // update the entity in the table
    entity.name = "Ryan".to_owned();
    entity_client.update(&entity, response.etag.into())?.await?;
    entity_client.delete().await?;

    /// delete the client now that we're done
    table_client.delete().await?;
    Ok(())
}

License: MIT

Dependencies

~8–24MB
~369K SLoC