6#include <userver/compiler/demangle.hpp>
7#include <userver/storages/postgres/detail/is_decl_complete.hpp>
8#include <userver/storages/postgres/io/pg_types.hpp>
9#include <userver/storages/postgres/io/traits.hpp>
10#include <userver/storages/postgres/io/type_traits.hpp>
12USERVER_NAMESPACE_BEGIN
17template <
typename T,
typename Enable = USERVER_NAMESPACE::
utils::void_t<>>
37template <
typename... T>
38inline bool ForceReference(
const T&...) {
42struct RegisterPredefinedOidParser {
43 static RegisterPredefinedOidParser Register(
52struct RegisterUserTypeParser {
53 static RegisterUserTypeParser Register(
const DBTypeName&, std::string cpp_name);
60struct CppToSystemPgImpl {
62 using Mapping = CppToSystemPg<T>;
63 static constexpr auto type_oid = Mapping::value;
64 static_assert(type_oid !=
PredefinedOids::kInvalid,
"Type oid is invalid");
67 static constexpr auto array_oid = ArrayMapping::value;
68 static_assert(array_oid !=
PredefinedOids::kInvalid,
"Array type oid is invalid");
74 static const inline RegisterPredefinedOidParser init = RegisterPredefinedOidParser::Register(
78 std::string{
compiler::GetTypeName<T>()}
81 static constexpr Oid GetOid(
const UserTypes&) {
83 return static_cast<Oid>(type_oid);
85 static constexpr Oid GetArrayOid(
const UserTypes&) {
87 return static_cast<Oid>(array_oid);
92struct CppToUserPgImpl;
97struct PgToCppPredefined {
98 static constexpr auto type_oid = TypeOid;
99 static_assert(type_oid !=
PredefinedOids::kInvalid,
"Type oid is invalid");
101 using ArrayMapping =
ArrayType<type_oid>;
102 static constexpr auto array_oid = ArrayMapping::value;
103 static_assert(array_oid !=
PredefinedOids::kInvalid,
"Array type oid is invalid");
107 static const inline RegisterPredefinedOidParser init = RegisterPredefinedOidParser::Register(
111 std::string{
compiler::GetTypeName<T>()}
120 std::enable_if_t<!
traits::kIsSpecialMapping<T> &&
traits::kIsMappedToPg<T> && !
traits::kIsMappedToArray<T>>>
121 : std::conditional_t<
traits::kIsMappedToSystemType<T>, detail::CppToSystemPgImpl<T>, detail::CppToUserPgImpl<T>> {};
124constexpr bool IsTypeMappedToSystem() {
125 return traits::kIsMappedToPg<T> &&
126 std::is_same<
typename CppToPg<T>::Mapping, CppToSystemPg<
typename CppToPg<T>::Type>>::value;
129void LogRegisteredTypes();