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 {
34 public:
35 using Name =
36 USERVER_NAMESPACE::utils::StrongTypedef<struct NameTag, std::string>;
37
38 Query(const char* text, std::optional<Name> = std::nullopt);
39 Query(std::string text, std::optional<Name> = std::nullopt);
40
41 const std::string& QueryText() const&;
42
43 const std::optional<Name>& QueryName() const&;
44
45 friend class Cluster;
46 friend class QueryTester;
47 friend class impl::Pool;
48
49 private:
50 template <typename... Args>
51 Query WithArgs(const Args&... args) const {
52 // we should throw on params count mismatch
53 // TODO : https://st.yandex-team.ru/TAXICOMMON-5066
54 return Query{fmt::format(fmt::runtime(text_), io::impl::Escape(args)...),
55 name_};
56 }
57
58 void FillSpanTags(tracing::Span&) const;
59
60 std::string text_;
61 std::optional<Name> name_;
62};
63
64} // namespace storages::clickhouse
65
66USERVER_NAMESPACE_END