Details
-
New Feature
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
None
-
None
-
Patch
Description
I've been looking for ways to enhance Groovy's SQL usability, and one thing I came up with is the use of named parameters which can in turn be mapped to bean properties. This is particularly handy for insert/ update statements, which usually require a long parameter list.
For example:
class Person { int id String firstName String lastName String address } def sql = new Sql(...) sql.executeUpdate( '''update person set first_name= :firstName, last_name= :lastName, addr= :address where id= :id''', somePerson )
Now, I realize using a GString is a similar alternative to passing the parameters as a list, but AFAIK it cannot be lazily evaluated if the actual SQL string is externalized and passed in at runtime. Correct? One possible improvement to this might be to allow a map as the 'model' and hierarchical property access as GStrings already allow.
Attached is an example class that extends groovy.sql.Sql, but if this was found to be a worthwhile feature, it could be a nice addition to the base Sql class.