Technology

I'm speaking at...

I teach and consult for

Spring, Hibernate, Grails, Rails and Maven training from the experts!
Training Calendar

Roo in Action

Soon in print!

Spring Roo in Action
MEAP Available Now!

Author, Roo in Action - in MEAP now
Manning Book Forum
My Roo Blog Entries
Srini Penchikala InfoQ

Twittery!

@krimple
@techcast
@gdickens
@RooInAction

I host the
Chariot TechCast

« Chariot TechCast reaches 40th episode (middle age?) | Main | My Philly Spring User Group slides and zip on Spring Roo »
Thursday
Sep032009

Using the gsql plugin for Griffon

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

 

PrintView Printer Friendly Version

EmailEmail Article to Friend

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>