I have a case class MyRecord that I want to use for every row in a resultset:
case class MyRecord(id: Int, remindeMe: Option[org.joda.time.DateTime])
How do I SELECT all rows in a table and return a List of MyRecord using Scala and Anorm with Play Framework?
I have tried with:
def getRecords() : List[MyRecord] = {
val records = SQL("SELECT id, data FROM mytable")().collect {
case Row(id: Int, Some(data: Long)) =>
MyRecord(id, new org.joda.time.DateTime(data))
}
}
If the column data is null I want None otherwise I want Some(data) as remindMe in the case class. Yes, the above Scala code is very wrong, but I don't understand how to solve this.