Scala noob here; for the life of me cannot see why I am not getting a result for this Anorm SQL call. When I run the SQL debug output it returns a result just fine but when run through the code I end up with an empty List().
Is there an issue with my RowParser? Why am I seeing good SQL in the debug output but it's not being collected by my result
val?
Am I missing something in my SQL .as()
to properly map the result rows to the Parser? When I remove the last result
line my result
val evaluates to a Unit, which is definitely suspicious.
// Case class - SQL results rows go into List of these
case class PerformanceData(
date: String,
kwh: String
)
// RowParser
val perfData = {
get[String]("reading_date") ~ get[String]("kwh") map{
case reading_date~kwh => PerformanceData(reading_date, kwh)
}
}
// SQL Call - function ret type is Seq[PerformanceData]
DB.withConnection("performance") { implicit connection =>
val result: Seq[PerformanceData] = SQL(
"""
SELECT CONCAT(reading_date) AS reading_date,
CONCAT(SUM(reading)) AS kwh
FROM perf
WHERE reading_date >= DATE_SUB(NOW(), INTERVAL 45 DAY)
AND sfoid IN ({sf_account_ids})
GROUP BY reading_date
ORDER BY reading_date DESC
LIMIT 30
"""
).on(
'sf_account_ids -> getSQLInValues(SFAccountIDs)
).as(
User.perfData *
)
// Logger.debug(result.toString) -> EMPTY LIST!??
result // Why is this necessary to return proper type?
}