* mroe quotes * dssf * listTables -> queryTables * move create/delete to the tableservice * one more batch * small refactor, added default data types * oops * clangs * table sas builder * sas test * cspell * add more test * cspell * hjhjh * clang * rename table-> tables * clang * partition and row key * clang why? * constructors, update tests * IT WORKSSSSS * PR comments * wqe * ewr * enum operator * clang * dsaada * sada * assets.json * clang * Update sdk/tables/azure-data-tables/inc/azure/data/tables/enum_operators.hpp Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * Update sdk/core/azure-core/test/ut/string_test.cpp Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com> * the = enums * assert and remove empty * compact string tests * clangs * complement * azureSasCredentials * PR cpmments * some extra * clang 11 --------- Co-authored-by: Anton Kolesnyk <41349689+antkmsft@users.noreply.github.com>
73 lines
2.0 KiB
C++
73 lines
2.0 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 = "table";
|
|
|
|
int main()
|
|
{
|
|
auto tableServiceClient = TableServiceClient::CreateFromConnectionString(GetConnectionString());
|
|
auto tableClient = TableClient::CreateFromConnectionString(GetConnectionString(), TableName);
|
|
|
|
// create new table
|
|
tableServiceClient.CreateTable(TableName);
|
|
|
|
// list tables
|
|
auto tables = tableServiceClient.QueryTables();
|
|
for (auto table : tables.Tables)
|
|
{
|
|
std::cout << table.TableName << std::endl;
|
|
}
|
|
// init new entity
|
|
Azure::Data::Tables::Models::TableEntity entity;
|
|
entity.PartitionKey = "P1";
|
|
entity.RowKey = "R1";
|
|
entity.Properties["Name"] = "Azure";
|
|
entity.Properties["Product"] = "Tables";
|
|
// create new entity
|
|
auto response = tableClient.CreateEntity(entity);
|
|
|
|
// update entity
|
|
std::cout << response.Value.ETag << std::endl;
|
|
entity.Properties["Product"] = "Tables2";
|
|
auto updateResponse = tableClient.UpdateEntity(entity);
|
|
std::cout << updateResponse.Value.ETag << std::endl;
|
|
|
|
// merge entity
|
|
entity.Properties["Product"] = "Tables3";
|
|
entity.ETag = updateResponse.Value.ETag;
|
|
auto updateResponse2 = tableClient.MergeEntity(entity);
|
|
|
|
// delete entity
|
|
std::cout << updateResponse2.Value.ETag << std::endl;
|
|
entity.ETag = updateResponse2.Value.ETag;
|
|
auto deleteResponse = tableClient.DeleteEntity(entity);
|
|
|
|
// delete existing table
|
|
tableServiceClient.DeleteTable(TableName);
|
|
return 0;
|
|
}
|