On 10/11/2013 06:25 PM, Dicebot wrote:

The very point of proposal is to not have any UDA's when information is already enough - same as it done in various vibe.d modules, configuration by convention.

I thought about extra fields in UserListItem that are not part of the
query result.

But after some more thought, I'm actually actually wondering whether
binding a fixed query to a type is a good idea in the first place,
because the type mainly serves as carrier of the UDA metadata.

     @dbexpr("FROM user ORDER BY username ASC")
     struct UserListItem
     {
         @dbexpr("user_id")
         int user_id;

         @dbexpr("username")
         string username;
     }
     const users = db.queryExpr!UserListItem;

IMHO a throwaway tuple type made more sense for a single query.

db.select!(Tuple!(int, "user_id", string, "username"))("FROM user ORDER 
BY username ASC");

If your targeting to express SQL schemata it should be more declarative,
maybe like so.

/// name of table
struct table { string name; }
/// optional: name of column in table
struct column { string name; }
/// primary key constraint
struct primaryKey {}
/// unique constraint
struct unique {}
/// references a foreign key
struct foreignKey(alias column) { alias key = column; }

@table("user")
struct User
{
     @primaryKey
     int id;

     string name;

     @column("bar") @unique
     string foo;

     @foreignKey!(City.name)
     string city;
}

@table("city")
struct City
{
     @primaryKey
     string name;
}

The declaration should give you enough information to implement the
following SQL statements.

db.select!("id", "name").from!User;
db.select.from!User;
db.select.from!User.orderBy!("name")(Order.ascend);

db.insertInto!User(User(0, "dawg", "code@dawg.eu", "Berlin"));

db.select.from!User.where!("id <=")(20);
db.select.from!User.where!("name LIKE")("foo*");