[odb-users] Same obect in multiple schemas with different table
names
Seymour, Robert
Robert.Seymour at arris.com
Sun Jan 17 13:27:04 EST 2016
Thanks Boris.
Using the same name is not a problem, appreciate the quick response.
- Rob
-----Original Message-----
From: Boris Kolpackov [mailto:boris at codesynthesis.com]
Sent: Sunday, January 17, 2016 1:06 AM
To: Seymour, Robert
Cc: odb-users at codesynthesis.com
Subject: Re: [odb-users] Same obect in multiple schemas with different table names
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>
void
print (const object<T>& o)
{
...
}
But if all you want is to avoid duplicating the classes, then this approach could work.
Boris
More information about the odb-users
mailing list