azure-data-tables
Loading...
Searching...
No Matches
tables_clients.hpp
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License. See License.txt in the project root for license information.
3
4#pragma once
5
6#include "azure/data/tables/credentials/azure_sas_credential.hpp"
7#include "azure/data/tables/credentials/named_key_credential.hpp"
8#include "azure/data/tables/models.hpp"
9
10#include <azure/core/credentials/credentials.hpp>
11#include <azure/core/http/http.hpp>
12#include <azure/core/http/policies/policy.hpp>
13#include <azure/core/internal/http/pipeline.hpp>
14#include <azure/core/internal/json/json.hpp>
15#include <azure/core/response.hpp>
16
17#include <cstdint>
18#include <memory>
19#include <string>
20#include <utility>
21#include <vector>
22
23#ifdef _azure_TABLES_TESTING_BUILD
24namespace Azure { namespace Data { namespace Tables { namespace StressTest {
25 class TransactionStressTest;
26}}}} // namespace Azure::Data::Tables::StressTest
27namespace Azure { namespace Data { namespace Test {
28 class TransactionsBodyTest_TransactionCreate_Test;
29 class TransactionsBodyTest_TransactionBodyInsertMergeOp_Test;
30 class TransactionsBodyTest_TransactionBodyInsertReplaceOp_Test;
31 class TransactionsBodyTest_TransactionBodyDeleteOp_Test;
32 class TransactionsBodyTest_TransactionBodyUpdateMergeOp_Test;
33 class TransactionsBodyTest_TransactionBodyUpdateReplaceOp_Test;
34 class TransactionsBodyTest_TransactionBodyAddOp_Test;
35}}} // namespace Azure::Data::Test
36#endif
37
38namespace Azure { namespace Data { namespace Tables {
39
40 namespace _detail {
44 constexpr static const char* ApiVersion = "2019-02-02";
48 constexpr static const char* TablesServicePackageName = "data-tables";
49 // various strings used in the library
50 constexpr static const char* OriginHeader = "Origin";
51 constexpr static const char* AccessControlRequestMethodHeader = "Access-Control-Request-Method";
52 constexpr static const char* ResrouceTypeService = "service";
53 constexpr static const char* ComponentProperties = "properties";
54 constexpr static const char* ContentTypeXml = "application/xml";
55 constexpr static const char* ContentTypeJson = "application/json";
56 constexpr static const char* ResourceTypeHeader = "restype";
57 constexpr static const char* CompHeader = "comp";
58 constexpr static const char* ContentTypeHeader = "Content-Type";
59 constexpr static const char* ContentLengthHeader = "Content-Length";
60 constexpr static const char* AcceptHeader = "Accept";
61 constexpr static const char* PreferHeader = "Prefer";
62 constexpr static const char* PreferNoContent = "return-no-content";
63 constexpr static const char* AcceptFullMeta = "application/json;odata=fullmetadata";
64 constexpr static const char* IfMatch = "If-Match";
65 constexpr static const char* PartitionKeyFragment = "(PartitionKey='";
66 constexpr static const char* RowKeyFragment = "',RowKey='";
67 constexpr static const char* ClosingFragment = "')";
68 constexpr static const char* Value = "value";
69 constexpr static const char* TableName = "TableName";
70 constexpr static const char* ODataEditLink = "odata.editLink";
71 constexpr static const char* ODataId = "odata.id";
72 constexpr static const char* ODataType = "odata.type";
73 constexpr static const char* ODataMeta = "odata.metadata";
74 constexpr static const char* ODataError = "odata.error";
75 } // namespace _detail
76
80 class ServiceVersion final {
81 public:
87 explicit ServiceVersion(std::string version) : m_version{std::move(version)} {}
88
94 bool operator==(const ServiceVersion& other) const { return m_version == other.m_version; }
95
101 bool operator!=(const ServiceVersion& other) const { return !(*this == other); }
102
107 std::string const& ToString() const { return m_version; }
108
113 AZ_DATA_TABLES_DLLEXPORT const static ServiceVersion V2019_02_02;
114
115 private:
116 std::string m_version;
117 };
118
123 class TablesAudience final
124 : public Azure::Core::_internal::ExtendableEnumeration<TablesAudience> {
125 public:
134 explicit TablesAudience(std::string tablesAudience)
135 : ExtendableEnumeration(std::move(tablesAudience))
136 {
137 }
138 };
139
143 struct TableClientOptions final : Azure::Core::_internal::ClientOptions
144 {
148 ServiceVersion ApiVersion{_detail::ApiVersion};
149
156
161 Azure::Nullable<TablesAudience> Audience;
162 };
163
167 class TableClient final {
168 public:
178 explicit TableClient(
179 std::string const& serviceUrl,
180 std::string const& tableName,
181 const TableClientOptions& options = {});
192 explicit TableClient(
193 const std::string& serviceUrl,
194 const std::string& tableName,
195 std::shared_ptr<Core::Credentials::TokenCredential> credential,
196 const TableClientOptions& options = {});
197
207 explicit TableClient(
208 const std::string& tableName,
209 std::shared_ptr<Azure::Data::Tables::Credentials::NamedKeyCredential> credential,
210 std::string url,
211 const TableClientOptions& options = {});
212
222 explicit TableClient(
223 const std::string& serviceUrl,
224 std::shared_ptr<Azure::Data::Tables::Credentials::AzureSasCredential> credential,
225 const std::string& tableName,
226 const TableClientOptions& options = {});
227
238 const std::string& connectionString,
239 const std::string& tableName,
240 const TableClientOptions& options = {});
241
249 Response<Models::TableAccessPolicy> GetAccessPolicy(Core::Context const& context = {});
250
259 Response<Models::SetTableAccessPolicyResult> SetAccessPolicy(
260 Models::TableAccessPolicy const& tableAccessPolicy,
261 Core::Context const& context = {});
262
271 Response<Models::AddEntityResult> AddEntity(
272 Models::TableEntity const& tableEntity,
273 Models::AddEntityOptions const& options = {},
274 Core::Context const& context = {});
275
284 Response<Models::UpdateEntityResult> UpdateEntity(
285 Models::TableEntity const& tableEntity,
286 Models::UpdateEntityOptions const& options = {},
287 Core::Context const& context = {});
288
297 Response<Models::MergeEntityResult> MergeEntity(
298 Models::TableEntity const& tableEntity,
299 Models::MergeEntityOptions const& options = {},
300 Core::Context const& context = {});
301
309 Response<Models::DeleteEntityResult> DeleteEntity(
310 Models::TableEntity const& tableEntity,
311 Core::Context const& context = {});
312
321 Response<Models::UpsertEntityResult> UpsertEntity(
322 Models::TableEntity const& tableEntity,
323 Models::UpsertEntityOptions const& options = {},
324 Core::Context const& context = {});
325
334 Models::QueryEntitiesOptions const& options = {},
335 Core::Context const& context = {});
336
345 Response<Models::TableEntity> GetEntity(
346 const std::string& partitionKey,
347 const std::string& rowKey,
348 Core::Context const& context = {});
349
357 Response<Models::SubmitTransactionResult> SubmitTransaction(
358 std::vector<Models::TransactionStep> const& steps,
359 Core::Context const& context = {});
360
361 private:
362#ifdef _azure_TABLES_TESTING_BUILD
363 friend class Azure::Data::Tables::StressTest::TransactionStressTest;
364 friend class Azure::Data::Test::TransactionsBodyTest_TransactionCreate_Test;
365 friend class Azure::Data::Test::TransactionsBodyTest_TransactionBodyInsertMergeOp_Test;
366 friend class Azure::Data::Test::TransactionsBodyTest_TransactionBodyInsertReplaceOp_Test;
367 friend class Azure::Data::Test::TransactionsBodyTest_TransactionBodyDeleteOp_Test;
368 friend class Azure::Data::Test::TransactionsBodyTest_TransactionBodyUpdateMergeOp_Test;
369 friend class Azure::Data::Test::TransactionsBodyTest_TransactionBodyUpdateReplaceOp_Test;
370 friend class Azure::Data::Test::TransactionsBodyTest_TransactionBodyAddOp_Test;
371#endif
372
373 std::string PreparePayload(
374 std::string const& batchId,
375 std::string const& changesetId,
376 std::vector<Models::TransactionStep> const& steps);
377 std::string PrepAddEntity(std::string const& changesetId, Models::TableEntity entity);
378 std::string PrepDeleteEntity(std::string const& changesetId, Models::TableEntity entity);
379 std::string PrepMergeEntity(std::string const& changesetId, Models::TableEntity entity);
380 std::string PrepUpdateEntity(std::string const& changesetId, Models::TableEntity entity);
381 std::string PrepInsertEntity(std::string const& changesetId, Models::TableEntity entity);
382 std::shared_ptr<Core::Http::_internal::HttpPipeline> m_pipeline;
383 Core::Url m_url;
384 std::string m_tableName;
385 };
386
390 class TableServiceClient final {
391 public:
398 explicit TableServiceClient(const TableClientOptions& options = {});
399
408 explicit TableServiceClient(
409 const std::string& serviceUrl,
410 const TableClientOptions& options = {});
411
421 explicit TableServiceClient(
422 const std::string& serviceUrl,
423 std::shared_ptr<Core::Credentials::TokenCredential> credential,
424 const TableClientOptions& options = {});
425
435 explicit TableServiceClient(
436 const std::string& serviceUrl,
437 std::shared_ptr<Azure::Data::Tables::Credentials::NamedKeyCredential> credential,
438 const TableClientOptions& options = {});
439
449 explicit TableServiceClient(
450 const std::string& serviceUrl,
451 std::shared_ptr<Azure::Data::Tables::Credentials::AzureSasCredential> credential,
452 const TableClientOptions& options = {});
453
463 const std::string& connectionString,
464 const TableClientOptions& options = {});
465
473 Response<Models::Table> CreateTable(
474 std::string const& tableName,
475 Core::Context const& context = {});
476
484 Response<Models::DeleteTableResult> DeleteTable(
485 std::string const& tableName,
486 Core::Context const& context = {});
487
496 const Models::QueryTablesOptions& options = {},
497 const Azure::Core::Context& context = {}) const;
498
505 Response<Models::SetServicePropertiesResult> SetServiceProperties(
506 Models::SetServicePropertiesOptions const& options = {},
507 Core::Context const& context = {});
508
515 Response<Models::TableServiceProperties> GetServiceProperties(
516 Core::Context const& context = {});
517
524 Response<Models::ServiceStatistics> GetStatistics(Core::Context const& context = {});
525
533 Response<Models::PreflightCheckResult> PreflightCheck(
534 Models::PreflightCheckOptions const& options,
535 Core::Context const& context = {});
546 TableClient GetTableClient(const std::string& tableName, TableClientOptions const& options = {})
547 const;
548
549 private:
550 std::shared_ptr<Core::Http::_internal::HttpPipeline> m_pipeline;
551 std::shared_ptr<Core::Credentials::TokenCredential> m_tokenCredential;
552 std::shared_ptr<Azure::Data::Tables::Credentials::NamedKeyCredential> m_namedKeyCredential;
553 Core::Url m_url;
554 };
555}}} // namespace Azure::Data::Tables
Query Entities result.
Definition models.hpp:771
Query tables paged response.
Definition models.hpp:99
Table Entity.
Definition models.hpp:480
API version for Tables service.
Definition tables_clients.hpp:80
bool operator!=(const ServiceVersion &other) const
Enable comparing between two versions.
Definition tables_clients.hpp:101
ServiceVersion(std::string version)
Construct a new Service Version object.
Definition tables_clients.hpp:87
std::string const & ToString() const
Returns string representation.
Definition tables_clients.hpp:107
bool operator==(const ServiceVersion &other) const
Enable comparing between two versions.
Definition tables_clients.hpp:94
AZ_DATA_TABLES_DLLEXPORT static const ServiceVersion V2019_02_02
API version 2019-12-12.
Definition tables_clients.hpp:113
Table Client.
Definition tables_clients.hpp:167
Response< Models::UpsertEntityResult > UpsertEntity(Models::TableEntity const &tableEntity, Models::UpsertEntityOptions const &options={}, Core::Context const &context={})
Upsert specified entity in a table.
Definition tables_clients.cpp:791
Models::QueryEntitiesPagedResponse QueryEntities(Models::QueryEntitiesOptions const &options={}, Core::Context const &context={})
Queries entities in a table.
Definition tables_clients.cpp:861
Response< Models::SetTableAccessPolicyResult > SetAccessPolicy(Models::TableAccessPolicy const &tableAccessPolicy, Core::Context const &context={})
Sets stored access policies for the table that may be used with Shared Access Signatures.
Definition tables_clients.cpp:564
Response< Models::AddEntityResult > AddEntity(Models::TableEntity const &tableEntity, Models::AddEntityOptions const &options={}, Core::Context const &context={})
Add entity in a table.
Definition tables_clients.cpp:637
static TableClient CreateFromConnectionString(const std::string &connectionString, const std::string &tableName, const TableClientOptions &options={})
Initializes a new instance of tableClient.
Definition tables_clients.cpp:430
Response< Models::DeleteEntityResult > DeleteEntity(Models::TableEntity const &tableEntity, Core::Context const &context={})
Deletes the specified entity in a table.
Definition tables_clients.cpp:759
Response< Models::TableEntity > GetEntity(const std::string &partitionKey, const std::string &rowKey, Core::Context const &context={})
Queries a single entity in a table.
Definition tables_clients.cpp:828
Response< Models::TableAccessPolicy > GetAccessPolicy(Core::Context const &context={})
Retrieves details about any stored access policies specified on the table that may be used with Share...
Definition tables_clients.cpp:591
Response< Models::MergeEntityResult > MergeEntity(Models::TableEntity const &tableEntity, Models::MergeEntityOptions const &options={}, Core::Context const &context={})
Merge entity in a table.
Definition tables_clients.cpp:714
Response< Models::UpdateEntityResult > UpdateEntity(Models::TableEntity const &tableEntity, Models::UpdateEntityOptions const &options={}, Core::Context const &context={})
Update entity in a table.
Definition tables_clients.cpp:669
Response< Models::SubmitTransactionResult > SubmitTransaction(std::vector< Models::TransactionStep > const &steps, Core::Context const &context={})
Submits a transaction.
Definition tables_clients.cpp:947
Table Service Client.
Definition tables_clients.hpp:390
Response< Models::SetServicePropertiesResult > SetServiceProperties(Models::SetServicePropertiesOptions const &options={}, Core::Context const &context={})
Set service properties.
Definition tables_clients.cpp:194
Response< Models::PreflightCheckResult > PreflightCheck(Models::PreflightCheckOptions const &options, Core::Context const &context={})
Pre flight check.
Definition tables_clients.cpp:172
TableClient GetTableClient(const std::string &tableName, TableClientOptions const &options={}) const
Get table client.
Definition tables_clients.cpp:135
Response< Models::Table > CreateTable(std::string const &tableName, Core::Context const &context={})
Creates a new table under the given account.
Definition tables_clients.cpp:452
Response< Models::ServiceStatistics > GetStatistics(Core::Context const &context={})
Get service statistics.
Definition tables_clients.cpp:247
Response< Models::DeleteTableResult > DeleteTable(std::string const &tableName, Core::Context const &context={})
Operation permanently deletes the specified table.
Definition tables_clients.cpp:613
Models::QueryTablesPagedResponse QueryTables(const Models::QueryTablesOptions &options={}, const Azure::Core::Context &context={}) const
Queries tables under the given account.
Definition tables_clients.cpp:503
static TableServiceClient CreateFromConnectionString(const std::string &connectionString, const TableClientOptions &options={})
Initializes a new instance of tableClient.
Definition tables_clients.cpp:154
Response< Models::TableServiceProperties > GetServiceProperties(Core::Context const &context={})
Get service properties.
Definition tables_clients.cpp:224
Audiences available for Blobs.
Definition tables_clients.hpp:124
TablesAudience(std::string tablesAudience)
Construct a new TablesAudience object.
Definition tables_clients.hpp:134
Add Entity options.
Definition models.hpp:592
Merge Entity options.
Definition models.hpp:650
Preflight check options.
Definition models.hpp:287
Query Entities options.
Definition models.hpp:733
Query Tables options.
Definition models.hpp:68
Set Service Properties options.
Definition models.hpp:261
Table Access Policy.
Definition models.hpp:427
Update Entity options.
Definition models.hpp:619
Upsert Entity options.
Definition models.hpp:580
Optional parameters for constructing a new TableClient.
Definition tables_clients.hpp:144
bool EnableTenantDiscovery
Definition tables_clients.hpp:155
ServiceVersion ApiVersion
Definition tables_clients.hpp:148
Azure::Nullable< TablesAudience > Audience
Definition tables_clients.hpp:161