[std.database] at compile time
Justin Whear
justin at economicmodeling.com
Fri Oct 14 13:29:54 PDT 2011
Graham Fawcett wrote:
>>
>> But you still won't be able to verify the columns to the actual database
>> scheme?
>
> One approach would be to write a separate tool that connects to the
> database and writes out a representation of the schema to a source
> file. At compile time, the representation is statically imported, and
> used to verify the data model.
>
> If we had preprocessor support, the tool could be run as such,
> checking the model just before passing the source to the compiler.
>
> Graham
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.
More information about the Digitalmars-d
mailing list