Can your programming language do this?

Nick Sabalausky a at a.a
Sun Jan 23 11:44:38 PST 2011


"Adam D. Ruppe" <destructionator at gmail.com> wrote in message 
news:ihhsv0$1fgf$1 at digitalmars.com...
> alias DataObjectFromSqlCreateTable!(import("db.sql"), "users") User;
>                                 // sql source code , table to fetch
>
> void main() {
>    auto obj = new User(null); // that null should actually be a db handle 
> if
> you want to be able to commit changes
>
>    // read/write access to the user table, with compile time
>    // type and name checks
>
>    obj.first = "Changing my name!";
>    obj.date_last_edited = getUTCtime();
>
>    obj.commitChanges(); // save your writes back to the database,
> (reasonably) efficiently
> }
>
>
>
> D can! It can dynamically make those DataObjects too, with the
> same syntax, but you lose compile time checks for obvious reasons.
>
>
> I just couldn't help but laugh a bit when I ran this thing through
> CTFE and found it actually worked, so figured I'd share a positive
> message with you guys :-)
>
> See my code here:
>
> http://arsdnet.net/dcode/database.d
>
> You might want a database implementation to play with too:
>
> http://arsdnet.net/dcode/mysql.d (best for this purpose so far)
> http://arsdnet.net/dcode/sqlite.d (but the others work too)
> http://arsdnet.net/dcode/postgres.d
>
> A simple db.sql file is here:
> http://arsdnet.net/dcode/db.sql
>
> It's just a list of CREATE TABLE commands. I ran the program over
> a far more complex file too and it worked, but it isn't a super
> smart parser so you can probably break it pretty easily. (for one,
> it is case sensitive where as standard SQL is not)

Sweet! I'd thought about doing something like that before, but frankly I'm 
glad someone beat me to it :)





More information about the Digitalmars-d mailing list