On Friday, 11 September 2015 at 23:47:42 UTC, Andrei Alexandrescu wrote:
1. Use lambdas, which seem to already do what you want:

db.get!Person.filter!(p => p.age > 21 && p.name == "Peter")

The way this'd go, the db.get!Person() call returns an input range of Person. Presumably introspection is being used to bind fields in the query such as "age" and "name" to static field names in struct Person. Then good old std.algorithm.filter takes care of the rest.

I'm instantiating the lambda with a fake p to capture the expression so I can translate it to whatever SQL, MongoDB, columnar db is used.

2. If you want to embed real SQL into D, use string-based DSLs.

Strings don't capture context, aren't typechecked, and require a complex CTFE parser.

db.get!Person.where!"age > 21 & name = ?"(name);


Reply via email to