
Arkadiy Vertleyb wrote:
"Rene Rivera" <grafikrobot@gmail.com> wrote
Here's part of a short example of what we are considering:
template <typename C> struct Person : rsi::db::schema::table_def< C, Person<C> > { column id; column first_name; column last_name; column address; column mail_address; column phone;
template <typename T> typename T::result_type operator()(T const & transform) { return transform( table("Person") <<= id("id") % integer[autoincrement] & not_null & primary_key
<<= first_name("first_name") % character(50)[varying] & not_null
<<= last_name("last_name") % character(50)[varying] & not_null
<<= address("address_id") >> Address<C>().id
<<= mail_address("mail_address_id") >> Address<C>().id
<<= phone("phone") % character(20)[varying] & not_null ); } };
Do I understand correctly that this code maps a database record into a C++ structure?
No :-)
Is it possible to enforce correct types here, instead of using universal "column" type?
It's possible, but not directly. Or at least as direct as an object-relational mapping would do it... The column type above only has a structural (as in declaring structure) function. It defines the fields the table has so that they can (a) be given a label in the def, (b) they can be referred to from other table definitions, and (c) they can be referred to from transforms. The generic declaration allows for any transformation on the schema. There would be transformations for data selection with queries, schema constructions, schema validations, object-relational mapping, etc. At the point when one does a transformation it would, at that point, check the types and applicability of the transformation based on the schema and the capabilities (the "C" above) which would restrict what can be done based on what is defined (schema) and what is possible (capabilities). -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com -- 102708583/icq - grafikrobot/aim - grafikrobot/yahoo