Slick中的Scala投影仅针对一列

10

我正在遵循Slick文档中有关自增字段的示例,但我在创建映射投影时遇到了问题...只有一个列。

case class UserRole(id: Option[Int], role: String)

object UserRoles extends Table[UserRole]("userRole") {
  def id = column[Int]("ID", O.PrimaryKey, O.AutoInc)
  def role = column[String]("ROLE")
  // ...
  def * = id.? ~ role <> (UserRole, UserRole.unapply _)
      // NEXT LINE ERRORS OUT
  def forInsert = role <> ({t => UserRole(None, t._1)}, {(r: UserRole) => Some((r.role))}) returning id   
}

错误是"value <> is not a member of scala.slick.lifted.Column[String]"
我认为将模式设计为以下形式会更有效率:
case class UserRole(role: String)

object UserRoles extends Table[UserRole]("userRole") {
  def role = column[Int]("ROLE", O.PrimaryKey)
  // ...
  def * = role <> (UserRole, UserRole.unapply _)

}

但是我开始收到与上面相同的错误。"value <> is not a member of scala.slick.lifted.Column[String]"
我到底在做什么?我只有一列,难道我没有投影了吗?如果是这样,我应该做些什么呢?
1个回答

7

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接