scalaplayframeworkslickplay-slick

value delete is not a member of slick.lifted.Query[T,T#TableElementType,Seq]


I am currently playing around with Play and play-slick. The following code gives me an error

class GenericRepository(protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider[JdbcProfile] {
  import driver.api._

  implicit val localDateTimeColumnType = MappedColumnType.base[LocalDateTime, Timestamp](
    d => Timestamp.from(d.toInstant(ZoneOffset.ofHours(0))),
    d => d.toLocalDateTime
  )

  protected trait GenericTable {
    this: Table[_] =>
    def id = column[Long]("id", O.PrimaryKey, O.AutoInc)
    def createdAt = column[LocalDateTime]("created_at")
    def updatedAt = column[LocalDateTime]("updated_at")
  }

  protected class CrudRepository[T <: AbstractTable[_] with GenericRepository#GenericTable](private val tableQuery: TableQuery[T]) {
    def all = db.run(tableQuery.to[List].result)
    def create(obj: T#TableElementType) = db.run(tableQuery returning tableQuery.map(_.id) += obj)
    def delete(id: Long) = db.run(tableQuery.filter(_.id === id).delete)
  }
}

Error:

value delete is not a member of slick.lifted.Query[T,T#TableElementType,Seq]

I already googled a lot but no solution worked for me. For instance I tried replacing 'import driver.api.' with 'import slick.driver.H2Driver.api.' without any luck.

I am using Scala 2.11.7 with play-slick 2.0.2 and Play 2.5.


Solution

  • EDIT: From your pasted code I see now your problem.

    Just change your definition to (I changed type parameters only):

    protected class CrudRepository[E, T <: Table[E] with GenericRepository#GenericTable](private val tableQuery: TableQuery[T]) {
        def all = db.run(tableQuery.to[List].result)
        def create(obj: T#TableElementType) = db.run(tableQuery returning tableQuery.map(_.id) += obj)
        def delete(id: Long) = db.run(tableQuery.filter(_.id === id).delete)
      }
    

    where Table is slick.relational.RelationalProfile.API.Table.

    Then instantiate your CrudRepository in following way:

    val crud = new CrudRepository[Redirect,RedirectsTable](Redirects)
    

    Otherthan that it's looking good.