Scala Play Framework Slick - 类型不匹配问题

时间:2013-10-28 07:45:54

标签: scala playframework playframework-2.0 slick play-slick

我正在关注this文档,试图整理一个简单的查询:

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")

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

    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
    - type mismatch; found : scala.slick.jdbc.StaticQuery0[models.Data.User] required: Option[models.Data.User]
    - type mismatch; found : scala.slick.jdbc.StaticQuery0[models.Data.User] required: Option[models.Data.User]

我在这里缺少什么?

Scala 2.10.3,Play Framework 2.2.0,Slick 1.0.1

更新:已解决:

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

0 个答案:

没有答案