Hmm although I was initially excited by this approach I think it does
have limitation as I'm not sure how you would handle variable
resolution. For example you can do:
User.find {
it.name = "fred"
}
but how would you do? :
def name = "fred"
User.find {
it.name = name
}
This seems to be impossible unless there is some way to resolve the
variable fred while in the context of visiting the AST. Can you do
this?
The other option is to used named queries like:
def q = User.createQuery {
it.name = ":name"
}
q.params = [ "name" : "fred" ]
def results = q.find()
Which isn't quite as cool and flexible.. Any thoughts?
Graeme
On 01/11/05, Graeme Rocher <
[hidden email]> wrote:
> Whoa.. this could be great! I'll take a look
>
> Graeme
>
> On 01/11/05, Dierk Koenig <
[hidden email]> wrote:
> > Hi guys,
> >
> > as I currently write the Groovy Sql chapter for the book,
> > I came across groovy.sql.DataSet and the SqlWhereVisitor.
> > That approach may also handy in the
> >
> > > def user = User.findByName(name)
> >
> > scenario since it would allow writing it as
> >
> > User.find { it.name == name }
> >
> > The SqlWhereVisitor actually works on the AST of the
> > Closure's expression and generates the SQL WHERE clause
> > from it.
> > I just learned about this possibility and I'm really
> > exited :-)
> >
> > cheers
> > Mittie
> >
>