userver: userver/storages/clickhouse/query.hpp Source File
Loading...
Searching...
No Matches
query.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/clickhouse/query.hpp
4/// @brief @copybrief storages::clickhouse::Query
5
6#include <string>
7
8#include <fmt/format.h>
9
10#include <userver/utils/fmt_compat.hpp>
11#include <userver/utils/strong_typedef.hpp>
12
13#include <userver/storages/clickhouse/io/impl/escape.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17namespace tracing {
18class Span;
19}
20
21namespace storages::clickhouse {
22
23namespace impl {
24class Pool;
25}
26
27class Cluster;
28class QueryTester;
29
30/// @brief Holds a query and its name.
31/// In case query is expected to be executed with parameters,
32/// query text should conform to fmt format
33class Query final {
34public:
35 using Name = USERVER_NAMESPACE::utils::StrongTypedef<struct NameTag, std::string>;
36
37 Query(const char* text, std::optional<Name> = std::nullopt);
38 Query(std::string text, std::optional<Name> = std::nullopt);
39
40 const std::string& QueryText() const&;
41
42 const std::optional<Name>& QueryName() const&;
43
44 friend class Cluster;
45 friend class QueryTester;
46 friend class impl::Pool;
47
48private:
49 template <typename... Args>
50 Query WithArgs(const Args&... args) const {
51 // we should throw on params count mismatch
52 // TODO : https://st.yandex-team.ru/TAXICOMMON-5066
53 return Query{fmt::format(fmt::runtime(text_), io::impl::Escape(args)...), name_};
54 }
55
56 void FillSpanTags(tracing::Span&) const;
57
58 std::string text_;
59 std::optional<Name> name_;
60};
61
62} // namespace storages::clickhouse
63
64USERVER_NAMESPACE_END