19 breaking releases

new 0.20.0 Apr 24, 2024
0.19.0 Jan 5, 2024
0.18.1 Dec 11, 2023
0.17.0 Nov 3, 2023
0.1.0 Jan 25, 2022

#837 in Network programming

Download history 78/week @ 2023-12-31 80/week @ 2024-01-07 213/week @ 2024-01-14 102/week @ 2024-01-21 70/week @ 2024-01-28 127/week @ 2024-02-04 138/week @ 2024-02-11 191/week @ 2024-02-18 136/week @ 2024-02-25 169/week @ 2024-03-03 484/week @ 2024-03-10 760/week @ 2024-03-17 439/week @ 2024-03-24 266/week @ 2024-03-31 289/week @ 2024-04-07 128/week @ 2024-04-14

1,123 downloads per month
Used in azure-storage-cli

MIT license

380KB
9K 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<()> {
    tracing_subscriber::fmt().init();

    // 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::access_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–22MB
~334K SLoC