I am trying to write a generic CRUD trait for Slick 2.0. The trait should a) provide generic methods to read/update/delete entities as well as b) abstract from the database. Following this slick example (database abstraction) and this article (CRUD trait) I came up with the following (shortened) code snippet:
trait Profile {
val profile: JdbcProfile
}
trait Crud[T <: AbstractTable[A], A] { this: Profile =>
import profile.simple._
val qry: TableQuery[T]
def countAll()(implicit session: Session): Int = {
qry.length.run
}
def getAll()(implicit session: Session): List[A] = {
qry.list // <-- type mismatch; found: List[T#TableElementType] required: List[A]
}
}
The code is invalid due to a type mismatch. The return type of the 2nd function seems to be of type List[T#TableElementType]
but needs to be List[A]. Any ideas on how to solve the issue. Additional references to further readings on generic Slick 2.0 operations are welcome too.