[odb-users] composite value type

Boris Kolpackov boris at codesynthesis.com
Mon Jun 2 10:19:25 EDT 2014


MM <finjulhich at gmail.com> writes:

>   std::vector<
>     std::tuple< boost::gregorian::year_based_generator*,
>                      boost::gregorian::year_based_generator**,*
>                      boost::posix_time::time_period[5u]
>     >
>   >  data_;
> Now for data_, I am not too sure what this maps to.

Me neither. I don't even understand the semantics of this let alone
what a sensible representation for it might be in the database.

> But the V part of the row cannot map simply as a couple of columns.

Normally, std::vector (and other containers) is mapped to a separate
table (container table) that stores the entries for all the objects (See
Chapter 5).

> Secondly, for the boost profile, I cannot see any mappings for the types I
> use here (time_period, year_based_generator). What kind of solution can
> I go for?

You cannot store a pointer to year_based_generator in a database. In fact,
to me, it seems like year_based_generator is not something that would
be stored in the database at all.

So if I were you I would first try to understand what it is this data
describes semantically and what a sensible persistent representation
for it might be (ODB cannot auto-magically do it for you).

Using a random number generator as an example (no idea if 
year_based_generator is anything even remotely similar; I could not
find any documentation on it). There is no "direct" way to store
it in the database. Instead, you need to come up with something
that would describe it that you can persist. And what that
representation might be depends on your application logic. Maybe
it is the seed and the last returned value (so that, for example,
you can continue from where you left off). Maybe it is just the
seed. Maybe some other internal state. And for some applications
it may not even make sense to store anything at all. You could
just create a fresh generator seeded, say, with current time.


More information about the odb-users mailing list