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, Args&&... args);
46 ExecuteResponse Execute(OperationSettings settings,
const Query& query, PreparedArgsBuilder&& builder);
48 ExecuteResponse Execute(
49 QuerySettings query_settings,
50 OperationSettings settings,
52 PreparedArgsBuilder&& builder
59 void Commit(OperationSettings settings = {});
65 PreparedArgsBuilder GetBuilder()
const;
70 TableClient& table_client,
71 NYdb::NTable::TTransaction ydb_tx,
73 OperationSettings&& rollback_settings
78 void MarkError()
noexcept;
81 void EnsureActive()
const;
83 TableClient& table_client_;
85 impl::StatsScope stats_scope_;
87 NYdb::NTable::TTransaction ydb_tx_;
88 OperationSettings rollback_settings_;
89 bool is_active_{
true};
92template <
typename... Args>
93ExecuteResponse Transaction::
Execute(
const Query& query, Args&&... args) {
94 auto builder = GetBuilder();
95 builder.AddParams(std::forward<Args>(args)...);
96 return Execute(OperationSettings{}, query, std::move(builder));
99template <
typename... Args>
100ExecuteResponse Transaction::Execute(OperationSettings settings,
const Query& query, Args&&... args) {
101 auto builder = GetBuilder();
102 builder.AddParams(std::forward<Args>(args)...);
103 return Execute(std::move(settings), query, std::move(builder));