How to apply a generic type to other classes generic in Scala

Slick ORM has a class called TableQuery. Its companion object applies the method:

def apply[E <: AbstractTable[_]]: TableQuery[E] =
macro TableQueryMacroImpl.apply[E]

I have a Users extends Table class that extends AbstractTable, so I can write this:

class Users(tag: Tag) extends Table[User](tag, "users") {..some code..}
val query = TableQuery[Users]

I want to generalize working with a database to create a Dao class

class Dao[A, B <: AbstractTable[A]] {
   private val query = TableQuery[B]
}

Here the compiler says: "The type of the class is required, but B is found." When I change B <: AbstractTable [A] to B: ClassTag, it does not start either.

So, what general type do I need to send it to TableQuery?

+4
source share

Source: https://habr.com/ru/post/1607904/


All Articles