#[macro_use] extern crate serde_derive; use azure_sdk_storage_table_rs::{CloudTable, TableClient, Continuation}; use std::error::Error; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] struct MyEntity { pub task_name: String, pub completed: bool } #[tokio::main] async fn main() -> Result<(), Box> { // First we retrieve the account name and master key from environment variables. let account = std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!"); let master_key = std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!"); let table_name = "ReminderLists"; let client = TableClient::new(&account, &master_key); let table = CloudTable::new(client, table_name); table.create_if_not_exists().await?; // insert the entity // let mut my_entity = table // .insert( // &row_key, // "100", // MyEntity { // task_name: "Itsy bitsy spider".to_owned(), // completed: false // }, // ) // .await?; // println!("entity inserted: {:?}", my_entity); // get the entity (notice the etag) // let ret: TableEntity = table // .get(&my_entity.partition_key, &my_entity.row_key, None) // .await? // .ok_or(AzureError::GenericErrorWithText( // "item not found after insertion".to_string(), // ))?; // println!("get_entity result == {:?}", ret); // now we update the entity passing the etag. // my_entity.payload.task_name = "Wheel on the bus".to_owned(); // let mut my_entity = table.update_entity(my_entity).await?; // println!("update_entity completed without errors: {:?}", my_entity); // my_entity.payload.task_name = "Going round and round".to_owned(); // my_entity.payload.completed = true; // let my_entity = table.insert_or_update_entity(my_entity).await?; // println!( // "insert_or_update_entity completed without errors: {:?}", // my_entity // ); // // get the entity again (new payload and etag) // let ret: TableEntity = table // .get(&my_entity.partition_key, &my_entity.row_key, None) // .await? // .ok_or(AzureError::GenericErrorWithText( // "item not found after update".to_string(), // ))?; // println!("get_entity result == {:?}", ret); let filter = "$filter=PartitionKey%20eq%20'xianghan'%20and%20completed%20eq%20true"; let mut cont = Continuation::start(); while let Some(entities) = table.execute_query::(Some(filter), &mut cont).await? { println!("segment: {:?}", entities); } Ok(()) }