我正在玩 Play Framework,现在我正在尝试使用简单的表“用户”访问 PostgreSQL 数据库,定义如下:
SELECT * FROM users;
id | first_name | last_name | email | password
-c--+------------+-----------+-------+----------
AI | text | text | text | text
在 Play 中,我有我的用户案例类:
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]
其次,我尝试使用以下链接 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...
你对我有什么线索吗?我现在迷路了……
谢谢!