userver: uPg: support for C++ 'strong typedef' idiom
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
uPg: support for C++ 'strong typedef' idiom

Within userver a strong typedef can be expressed as an enum class for integral types and as an instance of USERVER_NAMESPACE::utils::StrongTypedef template for all types. Both of them are supported transparently by the PostgresSQL driver with minor limitations. No additional code required.

Warning
The underlying integral type for a strong typedef MUST be signed as PostgreSQL doesn't have unsigned types

The underlying type for a strong typedef must be mapped to a system or a user PostgreSQL data type. Strong typedef type derives nullability from underlying type.

Using USERVER_NAMESPACE::utils::StrongTypedef example:

using StringTypedef = utils::StrongTypedef<struct TestTypedef, std::string>;
// This strong typedef will be nullable
using OptStringTypedef = utils::StrongTypedef<struct TestTypedef, std::optional<std::string>>;
using IntTypedef = utils::StrongTypedef<struct TestTypedef, pg::Integer>;

Using enum class example:

namespace sample {
enum class EnumStrongTypedef : int {};
} // namespace sample
template <>
struct storages::postgres::io::traits::CanUseEnumAsStrongTypedef<sample::EnumStrongTypedef> : std::true_type {};