[odb-users] Generate C++ classes from a DB

Andrew Hoffmeyer andy.hoffmeyer at turnkeycorrections.com
Tue Jan 28 09:08:12 EST 2014


I've developed my own pseudo-orm system to do this with a MySQL 
database, with a good deal of success.  it uses the information_schema 
database, which most modern RDBMSs have.  the code generator is written 
in C++, and uses a custom C++ wrapper that I wrote for the MySQL C API.  
it handles one-to-many foreign key relationships in both directions, but 
others are not directly supported yet, although I intend to make them 
work eventually.  I'd say it only took me a total of about a week of 
actual coding to develop it.  I'm not bragging, but rather illustrating 
that it's not impossible, or even difficult to do, if you have a little 
motivation and some spare time.  I have considered making an odb version 
of it, but just haven't had the time or ambition to do so.  if I ever 
do, I'll be happy to share the code.  I wish I could share what I have, 
but it is proprietary, and covered by the NDA I have at my job.

On 1/28/2014 3:27 AM, Johannes Lochmann wrote:
> If it is only for plain data structs vor classes this could be achieved
> quite easily with a scripting language of your choice and a bit of SQL, i
> guess...
> Am 28.01.2014 09:24 schrieb "Adrien G" <adrien_chem at hotmail.com>:
>
>> Thanks for your answer! Indeed i guess this is a tricky feature to
>> implement ^^ No i didnt want to link two db at once its actually two
>> different projects ;)
>> Once that said, imagine you have a db with hundred of tables, its insane
>> to code it by hand, for time and human errors reasons ^^ do you have a
>> roadmap for this feature ? Is there any other c++ lib which supports this ?
>>
>> Thanks and good luck :)
>>
>> Sent from my Windows Phone
>> ________________________________
>> From: Boris Kolpackov<mailto:boris at codesynthesis.com>
>> Sent: 28/01/2014 05:38
>> To: Adrien G<mailto:adrien_chem at hotmail.com>
>> Cc: odb-users at codesynthesis.com<mailto:odb-users at codesynthesis.com>
>> Subject: Re: [odb-users] Generate C++ classes from a DB
>>
>> Hi Adrien,
>>
>> Adrien G <adrien_chem at hotmail.com> writes:
>>
>>> Do you have some command examples to generate the C++ model that
>> reflects an
>>> existing DB? For example I'd like to generate C++ classes (using Qt
>>> bindings) to match an sqlite and mysql DB.
>> No, this is not supported, though it is on our TODO list. The problem
>> with this feature is that it is not exactly clear how to map tables to
>> classes in many cases. Mapping for things like relationships and
>> containers are not easy to deduce from the database schema. Also, you
>> seem to want to go a step further and have generated classes that
>> simultaneously match two schemas for two different databases. I don't
>> think we will ever support something like this; it is too AI'ish.
>>
>> Note also that you can always write the classes by hand and then map
>> them to your existing schema(s). In your case, while it may seem like
>> a tedious approach, it is probably the only one that has a chance of
>> actually working.
>>
>> Boris
>>

-- 
Andrew Hoffmeyer
Software Developer/Network Administrator
Turnkey Corrections/Turnkey Software Solutions
V: 715-386-5700
F: 715-386-9988



More information about the odb-users mailing list