[odb-users] Same obect in multiple schemas with different table names

Boris Kolpackov boris at codesynthesis.com
Sun Jan 17 04:06:08 EST 2016

Hi Robert,

Seymour, Robert <Robert.Seymour at arris.com> writes:

> Is it possible to have the same class in multiple schemas (-schema-name)
> that have different table names for sqlite?

No, each persistent C++ class in ODB gets a single set of SQL statements
and they have the table name hard-wired in them.

If you really have to have this, one way to do it would be via templates,
something along these lines:

template <typename>
class object

struct schema1_tag {};
struct schema2_tag {};

using schema1_object = object<schema1_tag>;
using schema2_object = object<schema2_tag>;

#pragma db object(schema1_object) table("name1")
#pragma db object(schema2_object) table("name2")

The biggest issue with this approach is that if you have common code that
must work with "both" objects, you will have to templatize it, for example:

template <typename T>
print (const object<T>& o)

But if all you want is to avoid duplicating the classes, then this approach
could work.


More information about the odb-users mailing list