On Mon, 25 Apr 2011 01:49:16 +0300, Robert Clipsham <rob...@octarineparrot.com> wrote:

On 24/04/2011 21:40, dsimcha wrote:
However, it seems others in the community are interested in a more
general SQL DB wrapper that can be used with a variety of backends.
Now that no GSoC database project has been accepted, we need to
consider other options for getting this done. I understand that there
are a lot of independent attempts, but I don't know the status of
them or which ones, if any, are targeting eventual inclusion in
Phobos.

I have a general SQL db wrapper (only wrapping SQLite currently), which I'd be happy to adapt and submit for phobos, I'm currently working on a complete rewrite though, so this may not be a great idea right now.

Example usage:
----
struct Post
{
     int id;
     DateTime time;
     string title;
     string content;
}

auto getPosts(long lim, long offs=0)
{
     with (new SqlQuery)
     {
         select("*").from("blog")
                    .limit(lim)
                    .offset(offs);
         return execute!(Post)();
     }
}
foreach(post; getPosts(10))
{
     // Operate on posts
}
----

The new interface makes the above even simpler, it will look something like (rather rough, I'm in the early stages of implementing it):
----
struct Post
{
     int id;
     DateTime time;
     string title;
     string content;
}

auto posts = new SqlitePersister!Post(new SqliteDb("my.db"));
foreach(post; posts[0..10])
{
     // Operate on posts
}
----

Of course, both of these provide (or will provide) an interface to allow for SQL statements to be executed directly.


Is it possible to see code somewhere? It would be interesting to get rid of
raw SQL, but retain access to it's parts - but I'm not sure how many constructs you can handle in this way - for example, what about complex queries with joins?
What about subqueries?

Reply via email to