userver: userver/storages/postgres/query.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
query.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/postgres/query.hpp
4/// @brief @copybrief storages::postgres::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::postgres {
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::postgres
49
50USERVER_NAMESPACE_END