Helper for enumerators that use Parse
and ToString
functions for conversions, mostly for autogenerated enums from chaotic.
A generated enum:
enum class GeneratedRainbow { kRed, kOrange, kYellow, kGreen, kCyan };
std::string
ToString(GeneratedRainbow value);
can be registered in the following way
template <>
static constexpr DBTypeName postgres_name = "__pgtest.rainbow";
};
After that the enum is mapped to the PostgreSQL type that can be created in the following way:
CREATE TYPE __pgtest.rainbow AS enum (
'red', 'orange', 'yellow', 'green', 'cyan'
)
Use it as usual:
auto res = GetConn()->Execute("select 'red'::__pgtest.rainbow");
EXPECT_EQ(res[0][0].As<GeneratedRainbow>(), GeneratedRainbow::kRed);
res = GetConn()->Execute("select $1", GeneratedRainbow::kYellow);
EXPECT_EQ(res[0][0].As<GeneratedRainbow>(), GeneratedRainbow::kYellow);
Definition at line 70 of file enum_types.hpp.