10

我正在遵循Slick 文档的指导方针,但我不明白我在这里做错了什么:

package models

import scala.slick.session.Database
import Database.threadLocalSession
import scala.slick.jdbc.{GetResult, StaticQuery => Q}
import javax.sql.DataSource
import Q.interpolation

object Data {

    case class User(user: String, password: String)

    lazy val db = Database.forName("default")

    def result: Option[User] = {
        db.withSession {
            sql"SELECT user, password FROM user WHERE user = 'user' AND password = 'pass'".as[User]
        }
    }

}

线

sql"SELECT user, password FROM user WHERE user = 'user' AND password = 'pass'".as[User]

给我这个:

Multiple markers at this line
    - could not find implicit value for parameter rconv: scala.slick.jdbc.GetResult[models.Data.User]
    - could not find implicit value for parameter rconv: scala.slick.jdbc.GetResult[models.Data.User]

我在这里做错了什么?

播放框架 2.2.0、Scala 2.10.3、Slick 1.0.1

4

1 回答 1

13

您需要提供从结果到用户的转换功能。直接从光滑的主页复制和改编:

implicit val getUserResult = GetResult(r => User(r.<<, r.<<))

或您链接的文档中的此部分

于 2013-10-27T21:13:07.827 回答