How can I avoid Slick's model declaration verbosity and repetitiveness
I am currently using Slick 1.x to access MySQL within playframework 2.1.3.
While generally Slick's features look pretty good, I cannot wrap my head
around how repetitive the declaration syntax is. I mean have a look at the
following code:
case class User
(id: Option[Long]
, firstName: String
, lastName: String
, email: String
, password: String
, status: String
, createDate: Long = Platform.currentTime
, firstLogin: Option[Long]
, lastLogin: Option[Long]
, passwordChanged: Option[Long]
, failedAttempts: Int = 0
)
object User extends Table[User]("COMPUTER") {
def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
def firstName = column[String]("firstName", O.NotNull)
def lastName = column[String]("lastName", O.NotNull)
def email = column[String]("mail", O.NotNull)
def password = column[String]("password", O.NotNull)
def status = column[String]("status", O.NotNull)
def createDate = column[Long]("createDate", O.NotNull)
def firstLogin = column[Long]("firstLogin", O.Nullable)
def lastLogin = column[Long]("lastLogin", O.Nullable)
def passwordChanged = column[Long]("passwordChanged", O.Nullable)
def failedAttempts = column[Int]("failedAttempts", O.NotNull)
def * = id.? ~ firstName ~ lastName ~ email ~ password ~ status ~
createDate ~ firstLogin.? ~ lastLogin.? ~ passwordChanged.? ~
failedAttempts <>(User.apply _, User.unapply _)
def autoInc = * returning id
}
It can't be right, that in order to have a simple case class and an access
object, I will have to declare each and every field three times. Is there
a way to avoid this error prone repetitiveness?
No comments:
Post a Comment