[std.database] at compile time

bls bizprac at orange.fr
Sat Oct 15 01:49:09 PDT 2011


Am 14.10.2011 22:29, schrieb Justin Whear:
> This is actually possible now. I wrote a little CTFE parser for CREATE
> TABLE... statements, used mysql to dump a db, then used import() to include
> the dump and parse it at compile-time. I was actually using it to generate
> classes which mapped to the contents of each table (i.e. a "things" table
> would result in a "Thing" class which mapped the fields as properties).
> Obviously you need to keep the db dump up to date via an external tool.

Cool! Hesitate to share the code?

I think we should have a two way tool.
1) Dump database structure and generate ORM classes.
2) ORM classes should validate against the database.  (classname == 
tablename, or f.i. class customer { string tablename = "contact";)  In 
case that the db-table does not exist, create it. In case that the ORM 
class is not in sync with the db-table a) alter the db-table or b) throw 
an exception. priority : datetimestamp.

tools : std.traits and the orange serialisation lib
my 2 cents


More information about the Digitalmars-d mailing list