我试图编写一个通用的查询执行器方法。它适用于insert
,update
,getList
。对于delete
代码没有编译。这有什么办法吗?
import scala.slick.driver.JdbcProfile
trait DBComponent {
val profile: JdbcProfile
import profile.simple._
def dbObject(): Database
}
trait QueryExecutor { this: DBComponent =>
import profile.simple._
def execute[T <: Rep[_], F, C[_]](query: Query[T, F, C]): List[F] = dbObject.withSession { implicit session: Session => query.list }
def executeUpdate[T <: Rep[_], F, C[_]](query: Query[T, F, C], value: F): Int = dbObject.withSession { implicit session: Session => query.update(value) }
def executeInsert[T <: Rep[_], F, C[_]](query: Query[T, F, C], value: F): Int = dbObject.withSession { implicit session: Session => query.insert(value) }
def executeDelete[T <: Rep[_], F, C[_]](query: Query[T, F, C]): Int = dbObject.withSession { implicit session: Session => query.delete }*/
//getting error => delete is not a member of QueryExecutor.this.profile.simple.Query[T,F,C]
}