<p dir="ltr">I like, nice work.</p>
<div class="gmail_quote">On 28 Oct 2012 02:35, "BLM768" <<a href="mailto:blm768@gmail.com">blm768@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I've recently been working with Ruby's ActiveRecord as part of my job, and I realized that D was powerful enough to make a similar abstraction layer. I've been playing with the idea for a little while, and I've put up some code at <a href="https://github.com/blm768/adbi" target="_blank">https://github.com/blm768/adbi</a><u></u>. It isn't nearly as comprehensive as ActiveRecord, but it captures the basic idea of representing database structures as objects/structs.<br>

<br>
Using it is something like this:<br>
<br>
module main;<br>
<br>
import std.stdio;<br>
<br>
import adbi.model;<br>
import adbi.sqlite3.database;<br>
<br>
struct Test {<br>
        mixin Model!"test";<br>
        <br>
        const(char)[] name;<br>
        double num;<br>
        mixin reference!("test2", "test2", Test2);<br>
}<br>
<br>
struct Test2 {<br>
        mixin Model!"test2";<br>
        int value;<br>
}<br>
<br>
int main(string[] args) {<br>
        auto db = new Sqlite3Database("test.db");<br>
        auto q = db.query("SELECT * FROM test;");<br>
        <br>
        Test.updateSchema(db);<br>
        Test2.updateSchema(db);<br>
        <br>
        auto range = ModelRange!Test(q);<br>
        <br>
        foreach(value; range) {<br>
                writeln(value);<br>
        }<br>
        <br>
        auto q2 = db.query("SELECT * FROM test, test2 WHERE test2_id = <a href="http://test2.id" target="_blank">test2.id</a>");<br>
        <br>
        auto r2 = ModelRange!(Join!(Test, Test2))(q2);<br>
        <br>
        foreach(j; r2) {<br>
                writeln(j);<br>
        }<br>
        <br>
        return 0;<br>
}<br>
<br>
This code prints out every entry in the "test" table, then prints the results of a join on the "test" and "test2" tables. The calls to updateSchema() set up some static members of Test and Test2; after these calls, the library does not perform any operations with the column names, which should make retrieving a record noticeably faster than in a system like ActiveRecord. The downside is that these functions must be called every time the database schema changes in a way that affects column order, but that should happen very rarely, if ever, in a typical application.<br>

<br>
The code is far from complete, but it's an interesting toy and might actually be useful for simple applications once some of the issues are ironed out.<br>
<br>
</blockquote></div>