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)
32 : builder_(std::move(builder)) {}
35 template <
typename... NamesValues>
36 void AddParams(NamesValues&&... names_values);
40 friend class Transaction;
41 friend class TableClient;
42 struct PreparedArgsWithKey;
44 NYdb::TParams Build() && {
return std::move(builder_).Build(); }
46 PreparedArgsWithKey operator<<(
const std::string& key);
48 NYdb::TParamsBuilder builder_;
52void PreparedArgsBuilder::
Add(
const std::string& name, T&& value) {
53 auto& param_builder = builder_.AddParam(impl::ToString(name));
54 Write(param_builder, std::forward<T>(value));
55 param_builder.Build();
58template <
typename... NamesValues>
59void PreparedArgsBuilder::AddParams(NamesValues&&... names_values) {
60 [[maybe_unused]]
decltype(
auto) result =
61 (*
this << ... << std::forward<NamesValues>(names_values));
62 static_assert(std::is_same_v<
decltype(result), PreparedArgsBuilder&>);
65struct PreparedArgsBuilder::PreparedArgsWithKey
final {
66 PreparedArgsBuilder& builder;
67 const std::string& key;
70 PreparedArgsBuilder& operator<<(T&& value)
const {
71 builder.Add(key, std::forward<T>(value));
76inline auto PreparedArgsBuilder::operator<<(
const std::string& key)
77 -> PreparedArgsWithKey {
78 return PreparedArgsWithKey{*
this, key};