[odb-users] Composite values, multiple values in primary key, and foreign constraints

quejacq at gmail.com quejacq at gmail.com
Thu Dec 8 19:56:40 EST 2011


Hello,

I came across ODB last week while searching for a good ORM solution in C++,
so please excuse if the answers to my questions seem obvious to advanced
users.


1. I'm trying to define a composite value for the class
boost::asio::ip::address, which can contain either an IPv4 or IPv6 address.
Because MySQL (for example) cannot handle the 128 bits of an IPv6 address
in a single integer field, I have to split it up in at least two columns.
>From what I understand in the manual and examples, I can create composite
value types using the "db value" pragma. However, it seems to me that I am
only able to do so if I create the classes myself and use the pragmas
accordingly.

When using the "distant pragma" (i.e. #pragma dv
value(boost::asio::ip::addess)), I get an error in boost asio's
address.hpp: "unnamed type in data member declaration". Anyway, event if it
worked, it leads to a problem where, in the end, ip::address contains
either an ip::address_v4 or ip::address_v6, and while ip::address_v6
contains an array of 16 unsigned chars, while ip::address_v4 has one of 4,
so the "automatic" mapping will IMHO fail.

Is there any way to map a class defined in some third-party library and
define someting like a value_traits for it to provide the requested mapping?


2. Every example carefully avoids the case of multiple values in the
primary key. While I thought it would be a simple matter of using multiple
"db id" pragmas, this leads to an error returned by the odb compiler. How
can I have a primary key made of a tuple? Do I have to define another class
just reserved for them?


3. The only mention of foreign keys in the manual is inside raw SQL queries
to the DBMS. How can I define foreign key constraints among tables of the
database?

Thank you for answering,

Quentin


More information about the odb-users mailing list