Scala Play 2.3.0 with Anorm - Can't use Pattern Matching (IntelliJ cannot resolve symbol Row)

ぐ巨炮叔叔 提交于 2019-12-31 07:09:10

问题


I am developing an application with Scala (2.11) and Play Framework (2.3.0) on IntelliJ IDEA. I'm using Anorm to retrieve data from my database (MySQL with MariaDB).

Here is my first test application (it works):

package controllers

import play.api.mvc._
import play.api.db._
import anorm._

case class Client(id: Int, nom: String, prenom: String)

object Application extends Controller {

  def index = Action {
    var result: List[(Int, String)] = List()
    val sqlQuery = SQL(
      """
        select idClient, nameClient from Clients
        where idClient = {idClient};
      """
    ).on("idClient" -> 1)

    DB.withConnection { implicit conn =>
      result = sqlQuery().map(row =>
        row[Int]("IDClient") -> row[String]("NameClient")
      ).toList

    }
    Ok(result.toString)
  }
}

This works fine. I get the name of my client correctly. However, when I try to use pattern matching, like this:

result = sqlQuery().collect {
  case Row(idClient: Int, nameClient: String) => idClient -> nameClient
}

IntelliJ gives me an error, stating that it "Cannot resolve Symbol Row". As far as I know, Row is defined in the Anorm library, and so is SQL. It doesn't make sense that SQL would be found and not Row...

What's happening?


回答1:


anorm.Row extractor is not there in Play 2.3 . As suggested you could use parser.



来源:https://stackoverflow.com/questions/24262062/scala-play-2-3-0-with-anorm-cant-use-pattern-matching-intellij-cannot-resolv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!