#azure-sdk #azure-storage #azure #storage #sdk #api-bindings #data-tables

azure_data_tables

Azure Table存储库,来自Azure SDK for Rust

19次重大版本发布

0.20.0 2024年4月24日
0.19.0 2024年1月5日
0.18.1 2023年12月11日
0.17.0 2023年11月3日
0.1.0 2022年1月25日

#3 in #azure-storage

Download history 512/week @ 2024-04-25 526/week @ 2024-05-02 462/week @ 2024-05-09 330/week @ 2024-05-16 389/week @ 2024-05-23 566/week @ 2024-05-30 580/week @ 2024-06-06 241/week @ 2024-06-13 388/week @ 2024-06-20 1152/week @ 2024-06-27 985/week @ 2024-07-04 1413/week @ 2024-07-11 1637/week @ 2024-07-18 1613/week @ 2024-07-25 1352/week @ 2024-08-01 1044/week @ 2024-08-08

5,927 每月下载量
用于azure-storage-cli

MIT许可证

380KB
9K SLoC

azure_data_tables

该包来自Azure SDK for Rust。它支持Azure Table存储

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(())
}

许可证:MIT

依赖项

~8–22MB
~328K SLoC