I am design a DAO in slick 3.0. The problem I have is that every table in my schema has these 3 common columns:
def id = column[UUID]("id", O.PrimaryKey)
def createdDate = column[Timestamp]("created_date")
def updatedDate = column[Timestamp]("updated_date")
Is there a design to put them into a trait and extend from all other schema class? I don't want to repeat copy and paste this piece of code multiple times.
One of my class is:
class EmailParameterSchema(tag: Tag) extends Table[EmailParameter](tag, "email_parameter") {
def id = column[UUID]("id", O.PrimaryKey)
def paramKey = column[String]("param_key")
def paramValue = column[String]("param_value")
def emailQueueId = column[UUID]("email_queue_id")
def createdDate = column[Timestamp]("created_date")
def updatedDate = column[Timestamp]("updated_date")
def * = (id, paramKey, paramValue, emailQueueId,createdDate,updatedDate) <> (EmailParameter.tupled, EmailParameter.unapply)
}
I have solved it. This is the shared schema:
trait CommonSchema[A] extends Table[A] {
def id = column[UUID]("id", O.PrimaryKey)
def createdDate = column[Timestamp]("created_date")
def updatedDate = column[Timestamp]("updated_date")
}
And this is how use it:
class EmailParameterSchema(tag: Tag) extends Table[EmailParameter](tag, "email_parameter") with CommonSchema[EmailParameter]{
def paramKey = column[String]("param_key")
def paramValue = column[String]("param_value")
def emailQueueId = column[UUID]("email_queue_id")
def * = (id, paramKey, paramValue, emailQueueId,createdDate,updatedDate) <> (EmailParameter.tupled, EmailParameter.unapply)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.