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
20/// @note You may write a query in `.sql` file and generate a header file with Query from it.
21/// See @ref scripts/docs/en/userver/sql_files.md for more information.
22class Query {
23public:
24 using Name = USERVER_NAMESPACE::utils::StrongTypedef<struct NameTag, std::string>;
25
26 enum class LogMode { kFull, kNameOnly };
27
28 Query() = default;
29
30 Query(const char* statement, std::optional<Name> name = std::nullopt, LogMode log_mode = LogMode::kFull);
31
32 Query(std::string statement, std::optional<Name> name = std::nullopt, LogMode log_mode = LogMode::kFull);
33
34 const std::optional<Name>& GetName() const;
35
36 const std::string& Statement() const;
37
38 /// @brief Fills provided span with connection info
39 void FillSpanTags(tracing::Span&) const;
40
41private:
42 std::string statement_{};
43 std::optional<Name> name_{};
44 LogMode log_mode_ = LogMode::kFull;
45};
46
47} // namespace storages
48
49USERVER_NAMESPACE_END