Play Framework + Slick 3.0.0 ProvenShape 问题中的简单 PostgreSQL 查询

Simple PostgreSQL query in Play Framework + Slick 3.0.0 ProvenShape issue

我正在玩 Play Framework,我现在正在尝试使用简单的 table "users" 访问 PostgreSQL 数据库,定义如下:

SELECT * FROM users;
id  | first_name | last_name | email | password 
-c--+------------+-----------+-------+----------
AI  | text       | text      | text  | text

在 Play 中,我有我的用户案例 class :

case class User(id: Int, mail: String, pwd: String, firstName: String, lastName: String)

我正在处理以下导入:

import play.api.db.slick.DatabaseConfigProvider
import slick.driver.PostgresDriver
import slick.driver.PostgresDriver._
import slick.lifted.Tag

我可以通过以下方式使用我的数据库

@Inject
// Inject Database config provider lib
var dbConfigProvider: DatabaseConfigProvider = _

val dbConfig = dbConfigProvider.get[PostgresDriver]

import dbConfig.driver._

我正在关注此地址上的 Slick 3.0.0 文档:http://slick.typesafe.com/doc/3.0.0/queries.html#queries。为了构建我的请求,我首先尝试执行以下操作:

class Users(tag: Tag) extends Table[(Int,String,String,String,String)](tag, "users") {
  def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
  def mail = column[String]("email")
  def pwd = column[String]("password")
  def firstName = column[String]("first_name")
  def lastName = column[String]("last_name")
  def * = (id,mail,pwd,firstName,lastName)
}

并没有成功:我的 IDE 说 Expression 不符合预期类型 ProvenShape,./activator compile

[...] could not find implicit value for parameter tt: slick.ast.TypedType[Int]

我第二次尝试使用以下 link slick.typesafe.com/doc/3.0.0/schemas.html#mapped-tables 并写了这个:

class Users(tag: Tag) extends Table[User](tag, "users") {
  def id = column[Int]("id", O.PrimaryKey, O.AutoInc)
  def mail = column[String]("email")
  def pwd = column[String]("password")
  def firstName = column[String]("first_name")
  def lastName = column[String]("last_name")
  def * = (id, mail, pwd, firstName, lastName) <> (User.tupled, User.unapply)
}

但是IDE无法识别“<>”符号,而且unapply方法中缺少args...

你有什么线索可以告诉我吗?我现在迷路了...

谢谢!

screenshot of intellij error

经过几个小时的研究,我终于找到了问题所在。要修复它,我有:

  • 已将 Slick 更新为 build.sbt 中的最新版本:

libraryDependencies ++= Seq( "com.typesafe.play" %% "play-slick" % "2.0.0", "com.typesafe.play" %% "play-slick-evolutions" % "2.0.0" )

  • 导入 api(不仅是驱动程序...)

import dbConfig.driver._ // THIS was the problem import dbConfig.driver.api._ // .api._ is important...

现在一切正常。