如何编写用于删除的通用查询执行器方法?

时间:2015-01-01 11:35:06

标签: slick slick-2.0

我试图编写一个通用的查询执行器方法。它适用于insertupdategetList。对于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]
}

0 个答案:

没有答案