简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM