azure-sdk-for-cpp/sdk/tables/azure-data-tables/samples/tables_getting_started.cpp
George Arama abeb4e797b
tables transactions samples (#5496)
* transactions samples

* cleanup sample, update readme
2024-04-08 12:28:04 -07:00

49 lines
1.1 KiB
C++

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include <azure/data/tables.hpp>
#include <cstdio>
#include <iostream>
#include <stdexcept>
#include <thread>
std::string GetConnectionString()
{
const static std::string ConnectionString = "";
if (!ConnectionString.empty())
{
return ConnectionString;
}
const static std::string envConnectionString = std::getenv("STANDARD_STORAGE_CONNECTION_STRING");
if (!envConnectionString.empty())
{
return envConnectionString;
}
throw std::runtime_error("Cannot find connection string.");
}
using namespace Azure::Data::Tables;
const std::string TableName = "sample1";
int main()
{
auto tableServiceClient = TableServiceClient::CreateFromConnectionString(GetConnectionString());
// create new table
tableServiceClient.CreateTable(TableName);
// query tables
auto tables = tableServiceClient.QueryTables();
// print table names
for (auto table : tables.Tables)
{
std::cout << table.TableName << std::endl;
}
// delete existing table
tableServiceClient.DeleteTable(TableName);
return 0;
}