3#include <ydb-cpp-sdk/client/params/params.h>
9#include <userver/ydb/impl/cast.hpp>
10#include <userver/ydb/io/traits.hpp>
12USERVER_NAMESPACE_BEGIN
19class PreparedArgsBuilder
final {
21 PreparedArgsBuilder(PreparedArgsBuilder&&)
noexcept =
default;
22 PreparedArgsBuilder& operator=(PreparedArgsBuilder&&) =
delete;
27 void Add(
const std::string& name, T&& value);
31 explicit PreparedArgsBuilder(NYdb::TParamsBuilder&& builder) : builder_(std::move(builder)) {}
34 template <
typename... NamesValues>
35 void AddParams(NamesValues&&... names_values);
39 friend class Transaction;
40 friend class TableClient;
41 struct PreparedArgsWithKey;
43 NYdb::TParams Build() && {
return std::move(builder_).Build(); }
45 PreparedArgsWithKey operator<<(
const std::string& key);
47 NYdb::TParamsBuilder builder_;
51void PreparedArgsBuilder::
Add(
const std::string& name, T&& value) {
52 auto& param_builder = builder_.AddParam(impl::ToString(name));
53 Write(param_builder, std::forward<T>(value));
54 param_builder.Build();
57template <
typename... NamesValues>
58void PreparedArgsBuilder::AddParams(NamesValues&&... names_values) {
59 [[maybe_unused]]
decltype(
auto) result = (*
this << ... << std::forward<NamesValues>(names_values));
60 static_assert(std::is_same_v<
decltype(result), PreparedArgsBuilder&>);
63struct PreparedArgsBuilder::PreparedArgsWithKey
final {
64 PreparedArgsBuilder& builder;
65 const std::string& key;
68 PreparedArgsBuilder& operator<<(T&& value)
const {
69 builder.Add(key, std::forward<T>(value));
74inline auto PreparedArgsBuilder::operator<<(
const std::string& key) -> PreparedArgsWithKey {
75 return PreparedArgsWithKey{*
this, key};