Operator overloading or alternatives to expression templates
Jacob Carlborg via Digitalmars-d
digitalmars-d at puremagic.com
Sat Sep 12 07:07:48 PDT 2015
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
More information about the Digitalmars-d
mailing list