Ditto 4.13.1
 
Loading...
Searching...
No Matches
Transaction.hpp
1#ifndef DITTO_TRANSACTION_H
2#define DITTO_TRANSACTION_H
3
4#include "QueryResult.hpp"
5
6#include <string>
7
8namespace ditto {
9
10class Store;
11
26private:
27 bool read_only = false;
28 std::string hint;
29
30public:
32 TransactionOptions() = default;
33
39
41 bool get_read_only() const;
42
49 TransactionOptions &set_hint(std::string hint);
50
52 const std::string &get_hint() const;
53};
54
58 std::string id;
59
62 std::string hint;
63
69 bool is_read_only = false;
70};
71
73void from_json(const nlohmann::json &j, TransactionInfo &c);
74
76void to_json(nlohmann::json &j, const TransactionInfo &c);
77
87
95namespace internal {
96
97void transaction_execute_cb(
98 void *env_ptr, dittoffi_result_dittoffi_query_result_ptr_t ffi_result);
99
100} // namespace internal
101
102// clang-format off
117// clang-format on
118class Transaction {
119 friend class Store;
120
121 friend void ditto::internal::transaction_execute_cb(
122 void *env_ptr, dittoffi_result_dittoffi_query_result_ptr_t ffi_result);
123
124 struct Impl;
125 std::unique_ptr<Impl> impl;
126
127 explicit Transaction(Impl *impl);
128
130 perform(Store &store, const TransactionOptions &options,
131 const std::function<TransactionCompletionAction(Transaction &)> &fn);
132
133#ifdef DITTO_INTERNAL_TESTING
134public:
135#endif
137
138private:
139public:
142
143 Transaction(const Transaction &) = delete;
144 Transaction &operator=(const Transaction &) = delete;
145 Transaction(Transaction &&) = default;
146 Transaction &operator=(Transaction &&) = default;
147
150
152 Store &get_store() const;
153
176 QueryResult execute(std::string query, nlohmann::json query_args = nullptr);
177};
178
179} // namespace ditto
180
181#endif
Represents the returned results when executing a DQL query, containing a QueryResultItem for each mat...
Definition QueryResult.hpp:121
Provides access to Collections and a transaction API.
Definition Store.hpp:65
TransactionInfo get_info() const
Provides information about the transaction.
QueryResult execute(std::string query, nlohmann::json query_args=nullptr)
Executes a DQL query and returns matching items as a query result.
Store & get_store() const
The Store this transaction belongs to.
~Transaction()
Destructor.
Options for configuring a transaction.
Definition Transaction.hpp:25
const std::string & get_hint() const
Get hint value.
TransactionOptions & set_hint(std::string hint)
Set a hint for the transaction, which is logged.
TransactionOptions()=default
Constructor sets read_only false and no hint
bool get_read_only() const
Get read_only value.
TransactionOptions & set_read_only(bool read_only)
Set a flag indicating whether the transaction is read-only.
Namespace for the Ditto C++ SDK types and functions.
Definition AbstractDocumentPath.hpp:19
TransactionCompletionAction
Represents an action that completes a transaction, by either committing it or rolling it back.
Definition Transaction.hpp:80
@ rollback
Represents the action of rolling back a transaction.
Definition Transaction.hpp:85
@ commit
Represents the action of committing a transaction.
Definition Transaction.hpp:82
Encapsulates information about a transaction.
Definition Transaction.hpp:56
std::string id
A globally unique ID of the transaction.
Definition Transaction.hpp:58
std::string hint
The user hint passed when creating the transaction, useful for debugging and testing.
Definition Transaction.hpp:62
bool is_read_only
Indicates whether mutating DQL statements can be executed in the transaction.
Definition Transaction.hpp:69