2

我正在尝试在游戏框架中使用 slick,但即使是最简单的示例也很困难。

这是我的代码:

case class Account (
  id: Int,
  email: String,
  password: String,
  permission: String
)

class Accounts(tag: Tag) extends Table[Account](tag, "account") {
  def id = column[Int]("id")
  def email = column[String]("email")
  def password = column[String]("password")
  def permission = column[String]("permission")

  def * = (id, email, password, permission)
}

当我编译这个时,我得到以下错误:

play.PlayExceptions$CompilationException: Compilation error[No matching Shape found.
Slick does not know how to map the given types.
Possible causes: T in Table[T] does not match your * projection. Or you use an unsupported type in a Query (e.g. scala List).
  Required level: scala.slick.lifted.ShapeLevel.Flat
     Source type: (scala.slick.lifted.Column[Int], scala.slick.lifted.Column[String], scala.slick.lifted.Column[String], scala.slick.lifted.Column[String])
   Unpacked type: models.Account
     Packed type: Any
]

谁能告诉我这里是否有问题?

谢谢

更多详细信息:

  • 斯卡拉 2.10
  • 光滑的 2.0.2
  • 流畅播放 0.6.0.1
  • 播放框架 2.3.1
4

2 回答 2

16

我发现了这个问题。我有一个冲突的伴随对象

如果你有一个伴生对象,你需要为你的 * 投影使用稍微不同的语法:

def * = (id, email, password, permission) <> ((Account.apply _).tupled, Account.unapply)
于 2014-06-27T08:26:16.617 回答
3

根据http://slick.typesafe.com/doc/2.0.2/schemas.html,我认为你的“*”投影方法应该是这样的:

def * = (id, email, password, permission) <> (Account.tupled, Account.unapply)
于 2014-06-26T21:08:07.013 回答