7#include <userver/storages/postgres/exceptions.hpp>
8#include <userver/storages/postgres/io/buffer_io.hpp>
9#include <userver/storages/postgres/io/buffer_io_base.hpp>
10#include <userver/storages/postgres/io/nullable_traits.hpp>
12#include <userver/utils/strong_typedef.hpp>
13#include <userver/utils/void_t.hpp>
15USERVER_NAMESPACE_BEGIN
44template <
typename Tag,
typename T,
45 USERVER_NAMESPACE::utils::StrongTypedefOps Ops,
typename Enable>
46inline constexpr bool kIsStrongTypedefDirectlyMapped =
54template <
typename Tag,
typename T,
63template <
typename Tag,
typename T,
70template <
typename Tag,
typename T,
75template <
typename Tag,
typename T,
95template <
typename T,
typename = USERVER_NAMESPACE::
utils::
void_t<>>
101constexpr bool CheckCanUseEnumAsStrongTypedef() {
102 if constexpr (CanUseEnumAsStrongTypedef<T>{}) {
103 static_assert(std::is_enum_v<T>,
104 "storages::postgres::io::traits::CanUseEnumAsStrongTypedef "
105 "should be specialized only for enums");
107 std::is_signed_v<std::underlying_type_t<T>>,
108 "storages::postgres::io::traits::CanUseEnumAsStrongTypedef should be "
109 "specialized only for enums with signed underlying type");
125template <
typename Tag,
typename T,
135 template <
typename Buffer>
142template <
typename StrongTypedef,
bool Categories =
false>
143struct StrongTypedefParser : BufferParserBase<StrongTypedef> {
144 using BaseType = BufferParserBase<StrongTypedef>;
145 using UnderlyingType =
typename StrongTypedef::UnderlyingType;
147 using BaseType::BaseType;
150 UnderlyingType& v =
this->value.GetUnderlying();
151 io::ReadBuffer(buffer, v);
155template <
typename StrongTypedef>
156struct StrongTypedefParser<StrongTypedef,
true>
157 : BufferParserBase<StrongTypedef> {
158 using BaseType = BufferParserBase<StrongTypedef>;
159 using UnderlyingType =
typename StrongTypedef::UnderlyingType;
161 using BaseType::BaseType;
164 const TypeBufferCategory& categories) {
165 UnderlyingType& v =
this->value.GetUnderlying();
166 io::ReadBuffer(buffer, v, categories);
172template <
typename Tag,
typename T,
186template <
typename Tag,
typename T,
195template <
typename Tag,
typename T,
206struct EnumStrongTypedefFormatter : BufferFormatterBase<T> {
207 using BaseType = BufferFormatterBase<T>;
208 using BaseType::BaseType;
210 template <
typename Buffer>
211 void operator()(
const UserTypes& types, Buffer& buf)
const {
212 io::WriteBuffer(types, buf,
213 USERVER_NAMESPACE::utils::UnderlyingValue(
this->value));
218struct EnumStrongTypedefParser : BufferParserBase<T> {
219 using BaseType = BufferParserBase<T>;
220 using ValueType =
typename BaseType::ValueType;
221 using UnderlyingType = std::underlying_type_t<ValueType>;
223 using BaseType::BaseType;
227 io::ReadBuffer(buffer, v);
228 this->value =
static_cast<ValueType>(v);