0
votes

I have read this SO post: Play 2.4 - Slick 3.0.0 - DELETE not working

but it seems not to work in my case.

I manage to insert or get some data from my PostgreSQL (9.1) database in my Play! 2.4 application, but I don't manage to perform some deletions.

Here is the very simple code of my controller:

package controllers

import javax.inject.Inject
import play.api.db.slick.DatabaseConfigProvider
import play.api.mvc._
import slick.driver.JdbcProfile
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
import slick.driver.PostgresDriver.api._
import models.Address

class Application @Inject()(dbConfigProvider: DatabaseConfigProvider) extends Controller {
  val dbConfig = dbConfigProvider.get[JdbcProfile]
  import dbConfig._
  import dbConfig.driver.api._

  def index = Action.async {
    db.run(addresses.filter(_.id === 1L).delete) map { res =>
      Ok(Json.toJson(res))
    }
  }
}

and my model Address:

case class Address(id: Option[Long], city: String)

object Address {

  class Addresses(tag: Tag) extends Table[Address](tag, "addresses") {
    def id = column[Long]("addressid", O.PrimaryKey, O.AutoInc)
    def city = column[String]("city")

    def * = (id.?, city) <>
      ((Address.apply _).tupled, Address.unapply)
  }

  lazy val addresses = TableQuery[Addresses]
}

The compilation error I get is: value delete is not a member of slick.lifted.Query[models.Address.Addresses,models.Address.Addresses#TableElementType,Seq]

I suspect that it comes from the imports, but I tried a lot of things without any improvement.

1
Can you please describe your error? Is it a compilation one, a null pointer exception, an unexpected behaviour, beavers gnawing at your ethernet cables, something else?Aldo Stracquadanio
Oops, I have edited my post.Simon

1 Answers

1
votes

I suspect that the problem is that you are importing the implicits needed for the delete function twice, thus generating an ambiguity and causing the compiler to give up on that:

import slick.driver.PostgresDriver.api._
import dbConfig.driver.api._

You don't probably need one of the two anyway, if you are trying to be generic (e.g. because you want to run tests over H2) try removing the PostgresDriver import. If that doesn't work try removing the inner import and leave PostgresDriver as the SO post you linked seemed to suggest that delete was (is?) not in the common API.