[odb-users] Alternate mapping of bool
Boris Kolpackov
boris at codesynthesis.com
Mon Apr 9 02:14:53 EDT 2018
Paul Stath <PStath at jmawireless.com> writes:
> Is there a simpler way than creating a "wrapper" object, something
> similar to:
>
> struct NullBool {
> bool value;
> }
>
> and then provide:
>
> template<>
> class value_trait<NullBool, id_test>
> {
> ...
> }
As the value_trait<> template suggests, you either need a different
C++ type (first template parameter) or a database type (second template
parameter) to make it differ from the default <bool, id_integer>.
The simplest way to achieve what you want is probably to map such
special null-bool's to a different database type, say TEXT (you
can still store them as "0" and "1" or NULL and "1"). Then, to
"activate" this semantics for certain members you simply specify
the TEXT type explicitly:
class object
{
#pragma db type("TEXT") null
bool b;
};
Boris
More information about the odb-users
mailing list