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 {
21public:
22 using Name = USERVER_NAMESPACE::utils::StrongTypedef<struct NameTag, std::string>;
23
24 enum class LogMode { kFull, kNameOnly };
25
26 Query() = default;
27
28 Query(const char* statement, std::optional<Name> name = std::nullopt, LogMode log_mode = LogMode::kFull);
29
30 Query(std::string statement, std::optional<Name> name = std::nullopt, LogMode log_mode = LogMode::kFull);
31
32 const std::optional<Name>& GetName() const;
33
34 const std::string& Statement() const;
35
36 /// @brief Fills provided span with connection info
37 void FillSpanTags(tracing::Span&) const;
38
39private:
40 std::string statement_{};
41 std::optional<Name> name_{};
42 LogMode log_mode_ = LogMode::kFull;
43};
44
45} // namespace storages
46
47USERVER_NAMESPACE_END