我正在关注这个文档,试图整理一个简单的查询:
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 框架 2.2.0、Slick 1.0.1
更新:已解决:
sql"SELECT user, password FROM user WHERE user = 'user' AND password = 'pass'".as[User].firstOption