DSL with keyword param keyword param...

24 views
Skip to first unread message

Kostas kougios

unread,
Oct 31, 2012, 7:52:34 PM10/31/12
to 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

unread,
Nov 1, 2012, 5:00:19 AM11/1/12
to Kostas kougios, scala...@googlegroups.com
You can get something like
X update Person ...

Konstantinos Kougios

unread,
Nov 1, 2012, 6:33:20 AM11/1/12
to 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

unread,
Nov 1, 2012, 10:37:21 AM11/1/12
to 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.

Reply all
Reply to author
Forward
0 new messages