6#include <unordered_map>
8#include <userver/storages/postgres/detail/is_decl_complete.hpp>
9#include <userver/storages/postgres/io/pg_types.hpp>
10#include <userver/utils/void_t.hpp>
12USERVER_NAMESPACE_BEGIN
42BufferCategory GetTypeBufferCategory(
const TypeBufferCategory&, Oid);
46 std::size_t operator()(
BufferCategory val)
const {
return std::hash<IntegerType>{}(
static_cast<IntegerType>(val)); }
49inline constexpr int kPgBinaryDataFormat = 1;
55 static constexpr std::size_t npos = std::numeric_limits<std::size_t>::max();
59 std::size_t length = 0;
60 const std::uint8_t* buffer =
nullptr;
62 std::string ToString()
const {
return {
reinterpret_cast<
const char*>(buffer), length}; }
71 const TypeBufferCategory& categories,
72 std::size_t length =
sizeof(T),
84template <
typename T,
typename Enable = USERVER_NAMESPACE::utils::void_t<>>
89template <
typename T,
typename Enable = USERVER_NAMESPACE::utils::void_t<>>
90struct BufferFormatter;
95template <
typename T,
typename Enable = USERVER_NAMESPACE::
utils::
void_t<>>
101template <
typename T,
typename Enable = USERVER_NAMESPACE::
utils::
void_t<>>
126inline constexpr bool kHasParser = HasParser<T>::value;
128inline constexpr bool kHasFormatter = HasFormatter<T>::value;
132constexpr bool CheckParser() {
134 kHasParser<T> || std::is_enum_v<T>,
135 "Type doesn't have a parser. Probably you forgot to include "
136 "file with parser or to define your own. Please see page "
137 "`uPg: Supported data types` for more information"
141 kHasParser<T> || !std::is_enum_v<T>,
142 "Type doesn't have a parser. Probably you forgot to include "
143 "file with parser, to define your own or to specialize "
144 "`storages::postgres::io::traits::CanUseEnumAsStrongTypedef`. "
145 "See page `uPg: Supported data types` for more information"
152constexpr void CheckFormatter() {
154 kHasFormatter<T> || std::is_enum_v<T>,
155 "Type doesn't have a formatter. Probably you forgot to include "
156 "file with formatter or to define your own. Please see page "
157 "`uPg: Supported data types` for more information"
161 kHasFormatter<T> || !std::is_enum_v<T>,
162 "Type doesn't have a formatter. Probably you forgot to include "
163 "file with formatter, to define your own or to specialize "
164 "`storages::postgres::io::traits::CanUseEnumAsStrongTypedef`. "
165 "See page `uPg: Supported data types` for more information"
175inline constexpr BufferCategory kParserBufferCategory = ParserBufferCategory<T>::value;
181constexpr auto DetectBufferCategory() {
182 if constexpr (kHasParser<T>) {
183 return ParserBufferCategoryType<
typename IO<T>::ParserType>{};
185 return BufferCategoryConstant<BufferCategory::kNoParser>{};
192inline constexpr BufferCategory kTypeBufferCategory = TypeBufferCategory<T>::value;
198struct CustomParserDefined : utils::IsDeclComplete<BufferParser<T>> {};
200inline constexpr bool kCustomParserDefined = CustomParserDefined<T>::value;
203struct CustomFormatterDefined : utils::IsDeclComplete<BufferFormatter<T>> {};
205inline constexpr bool kCustomFormatterDefined = CustomFormatterDefined<T>::value;