[odb-users] Basic issue

Boris Kolpackov boris at codesynthesis.com
Tue Sep 9 13:23:54 EDT 2014


Hi Bruce,

Bruce Cresanta <cresanta at me.com> writes:

> I’ve looked at composite types. These seem to be packed into one column.

Where do you get your information? Here is the first paragraph from the
section describing composite value types (Section 7.2, "Composite Value
Types"):

"A composite value type is a class or struct type that is mapped to more
 than one database column."


> I write schema’s by hand normally and I have a need for a composite
> primary key across two columns with foreign key constraints to two
> other tables (the one sides).

Section 7.2.1, "Composite Object Ids". If I understood you correctly,
you want to have a composite primary key that is also two foreign
keys. In ODB that would translate to a composite object id which
consists of two pointers to objects. This is not supported and is
also the kind of complexity that we would like not to get into.

However, remember, pointers to objects is just an "OO" way to represent
relationships. Nothing prevents you from "stepping one level down" and
modelling the relationship as just a pair of object ids:

#pragma db value
struct table_a_id
{
  int table_b_id;
  int table_c_id;
};

#pragma db object
struct table_a
{
  #pragma db id
  table_a_id id;
};

You can then load the pointed-to objects given their ids:

table_a_id id = ...;
shared_ptr<table_a> ta (db.load<table_a> (id));
shared_ptr<table_b> tb (db.load<table_b> (ta.id.table_b_id));
shared_ptr<table_c> tc (db.load<table_c> (ta.id.table_c_id));

In fact, if you want to be fancy, you can emulate the OO pointers
to objects by having transient pointers in the class and then using
database operation callbacks to automatically persist/load/update
these pointers.

> The answer to this question will tell me if I can actually use your
> product.

If you can't use ODB, that's fine. We are not trying to be all things
to all people.


> I also have a need for Left and Right Outer Joins.

You can do pretty much anything with a view. At the lowest level you
can spell out literal SQL query with ODB just providing help for
parameter binding and result set extraction.

Boris



More information about the odb-users mailing list