5#include <userver/tracing/span.hpp>
7#include <userver/ydb/builder.hpp>
8#include <userver/ydb/exceptions.hpp>
9#include <userver/ydb/impl/stats_scope.hpp>
10#include <userver/ydb/query.hpp>
11#include <userver/ydb/response.hpp>
12#include <userver/ydb/settings.hpp>
14USERVER_NAMESPACE_BEGIN
21class Transaction
final {
23 Transaction(Transaction&&)
noexcept =
default;
24 Transaction(
const Transaction&) =
delete;
25 Transaction& operator=(Transaction&&) =
delete;
26 Transaction& operator=(
const Transaction&) =
delete;
40 template <
typename... Args>
41 ExecuteResponse
Execute(
const Query& query, Args&&... args);
43 template <
typename... Args>
44 ExecuteResponse Execute(OperationSettings settings,
const Query& query,
47 ExecuteResponse Execute(OperationSettings settings,
const Query& query,
48 PreparedArgsBuilder&& builder);
50 ExecuteResponse Execute(QuerySettings query_settings,
51 OperationSettings settings,
const Query& query,
52 PreparedArgsBuilder&& builder);
58 void Commit(OperationSettings settings = {});
64 PreparedArgsBuilder GetBuilder()
const;
68 Transaction(TableClient& table_client, NYdb::NTable::TTransaction ydb_tx,
69 std::string name, OperationSettings&& rollback_settings)
noexcept;
73 void MarkError()
noexcept;
76 void EnsureActive()
const;
78 TableClient& table_client_;
80 impl::StatsScope stats_scope_;
82 NYdb::NTable::TTransaction ydb_tx_;
83 OperationSettings rollback_settings_;
84 bool is_active_{
true};
87template <
typename... Args>
88ExecuteResponse Transaction::
Execute(
const Query& query, Args&&... args) {
89 auto builder = GetBuilder();
90 builder.AddParams(std::forward<Args>(args)...);
91 return Execute(OperationSettings{}, query, std::move(builder));
94template <
typename... Args>
95ExecuteResponse Transaction::Execute(OperationSettings settings,
96 const Query& query, Args&&... args) {
97 auto builder = GetBuilder();
98 builder.AddParams(std::forward<Args>(args)...);
99 return Execute(std::move(settings), query, std::move(builder));