[英]Slick projection <> to a trait with companion object
我是Scala&Slick的新手,在实现用户帐户时遇到一些麻烦。
用户类和伴随对象:
case class User(id: Long, email: String, password: String, role: Role)
object User {
}
角色特征和伴侣对象:
sealed trait Role
object Role {
case object Administrator extends Role
case object NormalUser extends Role
}
UserRepository架构配置
import javax.inject.{ Inject, Singleton }
import play.api.db.slick.DatabaseConfigProvider
import slick.jdbc.JdbcProfile
import scala.concurrent.{ Future, ExecutionContext }
@Singleton
class UserRepository @Inject() (dbConfigProvider: DatabaseConfigProvider)(implicit ec: ExecutionContext) {
private val dbConfig = dbConfigProvider.get[JdbcProfile]
import dbConfig._
import profile.api._
private class UsersTable(tag: Tag) extends Table[User](tag, "users") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def email = column[String]("email")
def password = column[String]("password")
def role = column[String]("role")
def * = (id, email, password, role) <> ((User.apply _).tupled, (User.unapply _))
}
我在User.apply
和User.unapply
上User.apply
类型不匹配
[error] found : ((Long, String, String, models.Role)) => models.User
[error] required: ((Long, String, String, String)) => ?
[error] def * = (id, email, password, role) <> ((User.apply _).tupled, (User.unapply _))
我试过按照光滑文档1中的建议编写自己的函数类型,并尝试使用MappedColumnType
2创建自定义标量类型,但似乎都不起作用。
任何帮助将不胜感激!
错误在这里:
def role = column[String]("role")
应该有Role
而不是String
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.