Jestem nowy w Scala & Slick i mam problemy z implementacją kont użytkowników.
Klasa użytkownika i obiekt towarzyszący:
case class User(id: Long, email: String, password: String, role: Role)
object User {
}
Cecha roli i obiekt towarzyszący:
sealed trait Role
object Role {
case object Administrator extends Role
case object NormalUser extends Role
}
Konfiguracja schematu 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 _))
}
Dostaję niedopasowanie typu User.apply
i User.unapply
[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 _))
Próbowałem napisać własny typ funkcji, zgodnie z sugestią zręcznej dokumentacji 1 a także tworzenie niestandardowego typu skalarnego za pomocą MappedColumnType
2 ale żadne nie wydaje się działać.
Każda pomoc będzie bardzo ceniona!
Odpowiedzi:
0 dla odpowiedzi № 1Błąd jest tutaj:
def role = column[String]("role")
Powinno być Role
zamiast String
.