Sql query with anorm. Can not use pattern matching
Pergunta
The code snippet shown below is supposed to be used to retrieve some data from database.
import anorm._
object Instruction {
def findAll(date:String):List[RealTimeInstruction]={
query = SQL("""
select * from instructions where date > {dd}
""").on("dd"->date)
}
}
Then I would like to use pattern matching to execute the query and process the results.
However, when I attemp to use query.map(...)
I get the following:
value map is not a member of anorm SimpleSql.
How can I do it?
Solução
You need to create a ResultSetParser to parse the result set into somehting you can pattern match on. perhaps something like
val rowParser : RowParser[String~Date] = get[String]("instructions.name")~get[Date]("instructions.date")
val resultSetParser = rowParser *
(query as resultSetParser) map { case name~date => ... }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow