Context:
I am currently writing a small library that compiles sql strings at compile-time and generates query objects.

Something like this:

unittest
{
    mixin Sql!(q{
       select feed.url, feed.title
       from users
       join user_feeds as feed
       on users.id = feed.user
       where user.id = {user}
    }, DBInterface) UserFeeds;

    UserFeeds.Query query;
    query.user = 1; //some user

    auto con   = //Open db connection
    auto feeds = con.execute(query);
    foreach(f; feeds)
    {
        writef("Feed: %s\n\tTitle: %s\n", f.url, f.title);
    }
}

The parsing step does some amount work like validates the sql query, makes sure that tables "user" and "user_feed" exists in DBInterface and creates a query having "user" as input and a result type containing url, title with appropriate type.

Now the compile times for parsing a small number of queries are marginal. However, as the queries become more numerous and complex compile-times starts to become a problem.

Currently I "solve"tm long compile times by having the DBInterface and queries be compiled into a separate lib and linking to that lib from the main application.

Having a dedicated db lib fixes compile times for the main application. But I am wondering if it's possible to work on a lower level of granularity. Somehow "cache" the queries between compiles, without resorting to each query being compiled into it's own lib/object file.

Does D have any facilities that could make this possible?



Reply via email to