Using the gsql plugin for Griffon
Thursday, September 3, 2009 at 5:23PM Recently Andres Almiray has added a gsql plugin to Griffon. This is very cool, as it lets you configure datasources ala' grails, and then inject the Groovy SQL API into your controllers.
Here is how it works:
First, install the plugin by using the instruction
griffon install-plugin gsql 1.0-SNAPSHOT
Next, configure your database connection using the ./griffon-app/conf/DataSource.groovy file, the same way you would a grails app.
Once configured, you may use the withSql closure to inject the Groovy SQL object, pre-initialized via your data source, into your code. Here is a simple example:
def rows = [];
withSql { sql ->
sql.eachRow("select name from city") { row ->
rows << row.name
}
}
There, that wasn't so hard, now was it?
Programming note: I am recording a Chariot TechCast with Andres tonight and will have it posted sometime next week. Thanks, Andres!
Ken
chariot-news,
griffon,
groovy in
Groovy/Grails 


Reader Comments