[odb-users] Create odb class from sql schema / use an existent database

Boris Kolpackov boris at codesynthesis.com
Wed May 29 08:27:22 EDT 2013


Hi,

rkadeFR <contact at rkade.fr> writes:

> I have an existent DB, and would like to map it to
> some C++/ODB classes in order to use my DB.
>  
> Is there a possibility to generate the C++/ODB classes?

Currently, there is no support for automatically generating
C++ classes from database schema. But seeing that this feature
is requested a lot, we are planning to add this support soon.

I your case, would you prefer the C++ classes generated
from a .sql file containing your table definitions or by
connecting to the database directly?


> Or is there an efficient way for me using an existing DB
> with my C++ program?

Right now, if you want to use ODB with an existing database,
then you will need to create and map your C++ classes manually.
ODB allows you to map to custom tables, columns, and database
types, for example:

#pragma db table("PEOPLE")
class person
{
  ...

  #pragma db column("NAME") type("VARCHAR(50)")
  std::string name;  
};

There is also the 'schema/custom' example in the odb-examples package
that shows how to do it.

Boris



More information about the odb-users mailing list