userver: userver/storages/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/query.hpp
4/// @brief @copybrief storages::Query
5
6#include <optional>
7#include <string>
8
9#include <userver/utils/strong_typedef.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace tracing {
14class Span;
15} // namespace tracing
16
17namespace storages {
18
19/// @brief Holds a query, its name and logging mode
20class Query {
21 public:
22 using Name =
23 USERVER_NAMESPACE::utils::StrongTypedef<struct NameTag, std::string>;
24
25 enum class LogMode { kFull, kNameOnly };
26
27 Query() = default;
28
29 Query(const char* statement, std::optional<Name> name = std::nullopt,
30 LogMode log_mode = LogMode::kFull);
31
32 Query(std::string statement, std::optional<Name> name = std::nullopt,
33 LogMode log_mode = LogMode::kFull);
34
35 const std::optional<Name>& GetName() const;
36
37 const std::string& Statement() const;
38
39 /// @brief Fills provided span with connection info
40 void FillSpanTags(tracing::Span&) const;
41
42 private:
43 std::string statement_{};
44 std::optional<Name> name_{};
45 LogMode log_mode_ = LogMode::kFull;
46};
47
48} // namespace storages
49
50USERVER_NAMESPACE_END