On 2015-09-12 01:47, Andrei Alexandrescu wrote:

There's two canonical ways to do that.

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.

A database is really good at what it does. Therefore one wants the filter/where statement to be executed by the database, not the application code.

It would also be quite wasteful to have to create an instance of Person to make the comparison then realizing it doesn't fulfill the condition and throw it away.

I'm not sure how database protocols work but one definitely don't want to query the database for each row or return all the rows from the database.

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

The point is to _not_ use raw SQL.

--
/Jacob Carlborg

Reply via email to