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

Commit 598f4d9

Browse files
authored
Merge pull request #141 from ctaggart/tables_examples
a TableService example that lists all the tables
2 parents 69276b1 + fefda7f commit 598f4d9

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use azure_sdk_storage_core::client::Client;
2+
use azure_sdk_storage_table::table::TableService;
3+
use futures::future::*;
4+
use std::error::Error;
5+
use tokio_core::reactor::Core;
6+
7+
fn main() {
8+
code().unwrap();
9+
}
10+
11+
// We run a separate method to use the elegant quotation mark operator.
12+
// A series of unwrap(), unwrap() would have achieved the same result.
13+
fn code() -> Result<(), Box<dyn Error>> {
14+
// First we retrieve the account name and master key from environment variables.
15+
let account = std::env::var("STORAGE_ACCOUNT").expect("Set env variable STORAGE_ACCOUNT first!");
16+
let master_key = std::env::var("STORAGE_MASTER_KEY").expect("Set env variable STORAGE_MASTER_KEY first!");
17+
18+
let mut core = Core::new()?;
19+
20+
let client = Client::new(&account, &master_key)?;
21+
let table_service = TableService::new(client);
22+
23+
let future = table_service.list_tables().and_then(move |tables| {
24+
println!("Account {} has {} tables(s)", account, tables.len());
25+
for ref table in tables {
26+
println!("{}", table);
27+
}
28+
Ok(())
29+
});
30+
31+
core.run(future)?;
32+
Ok(())
33+
}

0 commit comments

Comments
 (0)