I'm trying to template-out a TableQuery member but the path dependant types are messing me up. I've got a typical code-generated table like so:
trait TablesContainer {
case class MembersRow(firstName:String, lastName:String)
class Members(_tableTag: Tag) extends Table[MembersRow](_tableTag, Some("dbo"), "MEMBERS") {
def * = (firstName, lastName) <> (MembersRow.tupled, MembersRow.unapply)
val firstName: Rep[String] = column[String]("FIRM_NAME")
val lastName: Rep[String] = column[String]("LAST_NAME")
}
}
Then I try to create a class that will take a TableQuery (in the typical multi-db pattern) like so:
class TemplateHolder(profile: RelationalProfile) {
import profile.api._
class InsertionTemplate[T <: Table[E], E](tableQuery: TableQuery[T]) {
def apply(insertRow:E) = {
tableQuery += insertRow
}
}
}
Then I want to use it like so:
def template = new InsertionTemplate(TableQuery[TablesContainer.Members])
template.apply(MembersRow("Joe", "Bloggs"))
Only I get errors:
Error:(134, 28) inferred type arguments [com.test.TablesContainer.Members,Nothing] do not conform to class InsertionTemplate's type parameter bounds [T <: RelationalProfileConstants.this.profile.api.Table[E],E]
def template = new InsertionTemplate(TableQuery[TablesContainer.Members])
and then this one:
Error:(134, 60) type mismatch;
found : slick.lifted.TableQuery[com.test.TablesContainer.Members]
required: RelationalProfileConstants.this.profile.api.TableQuery[T]
(which expands to) slick.lifted.TableQuery[T]
def template = new InsertionTemplate(TableQuery[TablesContainer.Members])
What am I doing wrong?