In a Play application, I have a few tables and classes that share the same structure. I want to keep them different to maintain application semantics (yay static typing!). However, I'd like to avoid duplicating boilerplate code.
For example, here's class Region.
case class Region(id: Int, name:String)
and here is its Slick's table query class:
class RegionsTable(tag:Tag) extends Table[Region](tag, "regions") {
def id = column[Int]("id", O.AutoInc, O.PrimaryKey)
def name = column[String]("name", O.Unique)
def * = (id, name) <> (Region.tupled, Region.unapply)
}
How can I avoid duplicating the table query class for each of the other classes that share Region's structure?
Perhaps not very Slick native solution, but refactoring might look like:
Working Scatie example: https://scastie.scala-lang.org/fR7BzS1jSKSXptE9CTxXyA