Does anybody know what is the best approach to accessing a sql view through Grails (or if this is even possible)? It seems an obvious way of doing this would be to use execu
You can use plain SQL in Grails which is in the case of accessing a view the preferable way (IMO):
For example in your controller:
import groovy.sql.Sql
class MyFancySqlController {
def dataSource // the Spring-Bean "dataSource" is auto-injected
def list = {
def db = new Sql(dataSource) // Create a new instance of groovy.sql.Sql with the DB of the Grails app
def result = db.rows("SELECT foo, bar FROM my_view") // Perform the query
[ result: result ] // return the results as model
}
}
and the view part:
${it.foo}
${it.bar}
I hope the source is self-explanatory. The Documentation can be found here