DSL with keyword param keyword param...

24 Aufrufe
Direkt zur ersten ungelesenen Nachricht

Kostas kougios

ungelesen,
31.10.2012, 19:52:3431.10.12
an scala...@googlegroups.com
Hi all, I am trying to create a DSL like the update sql:

update Person set name="x" where ....

I've created an object with an update method, but my problem is that for someone to use it they need to write the code as:

update(Person) set name="x" where ....

instead of the more natural

update Person set name="x" where ....

So the parenthesis seem to be mandatory, at least the way I implemented it.

Any ideas on an impl that doesn't require parenthesis?

Naftoli Gugenheim

ungelesen,
01.11.2012, 05:00:1901.11.12
an Kostas kougios, scala...@googlegroups.com
You can get something like
X update Person ...

Konstantinos Kougios

ungelesen,
01.11.2012, 06:33:2001.11.12
an Naftoli Gugenheim, scala...@googlegroups.com
Thanks Naftoli, yes I do that for i.e. selects:

select from Person ...

and this works in a similar way to
list map {...}

But I can't get it to work with 1 keyword only:

update Person ... // doesn't compile

Razvan Cojocaru

ungelesen,
01.11.2012, 10:37:2101.11.12
an Konstantinos Kougios, Naftoli Gugenheim, scala...@googlegroups.com

Make the update an object and the Person a method taking a set of modifiers, maybe that works, although not easily extensible – sorry, no time to play with it here. Maybe one way to extend it is via implicits for each new Table?

 

Another approach I used in the past was to define another object which looks like a prompt or starting point, so you’d write

 

$ update Person…

 

It’s easy to add for the other one

 

$ select from Person…

 

This version is much more easily extensible – Person can be any >: Table or alike.

Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten