How do you invoke database functions from grails?
Such as the CONVERT(decimal, timestamp)
Without using groovy SQL like this:
def sql = new Sql(dataSource)
I would like to avoid any SQL statements and take full advantage of the grails magic.
My understanding is that grails does not have native support for database functions. You will need to write SQL. Gorm is an abstraction of Hibernate, you may want to refer to:
In your Domain class First you must -
import groovy.sql.Sql
Then you can create Sql instance and call a function like below -
def date = "'21-Feb-19 14:10:10.123000'"
def timestamp_format = "'DD-Mon-RR HH24:MI:SS.FF'"
String query = 'select to_timestamp('+date+','+timestamp_format+') from dual'
def sql = Sql.newInstance('url', 'username', 'password', 'driverClassName')
def result= sql.rows(query);
def rows = result.collect{it.values()}
println rows