Chariot Training Classes

Training Courses

I run Chariot's training and mentoring services. We provide training in AngularJS, HTML5, Spring, Hibernate, Maven, Scala, and more.

Chariot Education Services

Technology

Chariot Emerging Tech

Learn about upcoming technologies and trends from my colleagues at Chariot Solutions.

Resources

Chariot Conferences

Podcasts

« 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>