현재 Slick 1.x를 사용하여 playframework 2.1.3 내에서 MySQL에 액세스하고 있습니다. 일반적으로 Slick의 기능이 꽤 좋아 보이지만 선언 구문이 얼마나 반복적인지에 대해 머리를 감쌀 수는 없습니다. 다음 코드를 살펴 보겠습니다.
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]("USER") {
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
}
간단한 케이스 클래스와 액세스 객체를 가지려면 각 필드를 세 번 선언해야한다는 것은 옳지 않습니다. 이 오류가 발생하기 쉬운 반복을 피할 수있는 방법이 있습니까?
업데이트 : 물론이 문제에 대한 해결책은 읽기 및 쓰기 작업을 지원해야 합니다.
코드 생성 또는 향후 유형 공급자를 사용할 수 있습니다.
참조 https://groups.google.com/d/msg/scalaquery/Pdp3GTXsKCo/O0e3JLXAaK8J를
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다