I'm trying to create a generic abstract class table and create a generic TableQuery
using it with slick
The generic Table:
trait TaskRow {
def dvProjectId: Int
def timestamp: Long
def status: String
}
abstract class TaskTable[T](tag: Tag, name: String) extends Table[T](tag, name) {
def id: Rep[Int] = column[Int]("Id")
def status: Rep[String] = column[String]("Status")
}
Usage:
case class ATaskRow(id: Int, status: String) extends TaskRow
class ATaskTable(tag: Tag) extends TaskTable[ATaskRow](tag, "A") {
def * : ProvenShape[ATaskRow] = (id, status) <> (ATaskRow.tupled, ATaskRow.unapply)
}
class Repo[T <: TaskTable[R], R <: TaskRow] @Inject()(db: DB) {
...
private def table: TableQuery[T] = TableQuery[T]
}
this line gives an error - class type required but T found
:
private def table: TableQuery[T] = TableQuery[T]
There's a way I can fix it?
So I solved this.
class ARepo @Inject()(db: DB)
extends Repo[ATaskTable, ATaskRow](db, (tag: Tag) => new ATaskTable(tag))
class Repo[T <: TaskTable[R], R <: TaskRow] (db: DB, cons: Tag => T) {
...
private def table: TableQuery[T] = TableQuery(cons)
}