opEquals() non-standard return type
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Jan 23 17:28:37 UTC 2019
On Wed, Jan 23, 2019 at 03:19:06PM +0000, Jacob Shtokolov via Digitalmars-d-learn wrote:
> Hi,
>
> I'm trying to check whether it's possible to implement Python's
> SQLAlchemy-like query syntax in D, but I get stuck a bit.
>
> Here is a simple example of what I want to achieve:
>
> ```
> auto result = User.filter(User.id == 10);
> result = User.filter(User.name == "John");
> result = User.filter(User.age > 18);
> ```
[...]
The best way to do this is to use a string DSL or a delegate as template
argument. For example:
auto result = User.filter!q{ User.name == "John" };
or:
auto result = User.filter!(u => u.name == "John");
The delegate option will be easier to implement, but the syntax will be
slightly more verbose. The string DSL option will give you the best
syntax, but then you'll have to implement a compile-time DSL parser.
T
--
Bare foot: (n.) A device for locating thumb tacks on the floor.
More information about the Digitalmars-d-learn
mailing list