userver: userver/storages/postgres/message.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
message.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/postgres/message.hpp
4/// @brief Database messages
5
6#include <optional>
7#include <string>
8#include <string_view>
9
10#include <userver/logging/log_extra.hpp>
11
12#include <userver/storages/postgres/postgres_fwd.hpp>
13#include <userver/storages/postgres/sql_state.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17namespace storages::postgres {
18
19class Message {
20public:
21 enum class Severity { kLog, kDebug, kInfo, kNotice, kWarning, kError, kFatal, kPanic };
22
23 explicit Message(detail::ResultWrapperPtr);
24
25 std::string GetMessage() const;
26 std::string GetPrimary() const;
27 std::string GetDetail() const;
28 Severity GetSeverity() const;
29 std::string GetSeverityString() const;
30 SqlState GetSqlState() const;
31
32 std::string GetSchema() const;
33 std::string GetTable() const;
34 std::string GetColumn() const;
35 std::string GetDatatype() const;
36 std::string GetConstraint() const;
37
38 logging::LogExtra GetLogExtra() const;
39
40 /// @brief Throw an exception according to the SQL code
41 void ThrowException() const;
42
43 static Severity SeverityFromString(std::string_view);
44
45 /// This constant is returned from Message::Get* functions if the PostgreSQL failed retrieve some info.
46 static constexpr const char* kUnknown = "<unknown>";
47
48private:
49 detail::ResultWrapperPtr res_;
50};
51
52} // namespace storages::postgres
53
54USERVER_NAMESPACE_END