Operator overloading or alternatives to expression templates
Sebastiaan Koppe via Digitalmars-d
digitalmars-d at puremagic.com
Mon Sep 14 06:47:08 PDT 2015
On Friday, 11 September 2015 at 19:41:41 UTC, Martin Nowak wrote:
> Does anyone have a different idea how to make a nice query
> language? db.get!Person.where!(p => p.age > 21 && p.name ==
> "Peter")
In our last project we took the following approach:
`auto q = query.builder!Person.age!">"(20).name("Peter");`
In the query-builders there was a lot of ugly concatenating sql
stuff. But there was just one guy writing that, everybody else
was using the high-level functions.
It allows for a lot of checking, not only on types but also on
logic (e.g. age!">"(20).age!"<"(10) was caught at runtime). Plus,
very unittestable.
It worked so well that once the query-builders were written, all
the constraints, sorting and ordering parameters could be passed
straight from the http api down to the query-builders.
Still, you would have to write the query-builders for each Object
you want query, although that is something you could do in a DSL.
More information about the Digitalmars-d
mailing list