10

I am trying to upgrade to Slick 3.0.0 and Play 2.4 (Scala), but deleting rows is not working. In the code below, everything works: querying all rows, inserting and updating - except delete.

package dao

import scala.concurrent.Future
import models._
import models.Tables._
import play.api.Play
import play.api.db.slick.DatabaseConfigProvider
import play.api.db.slick.HasDatabaseConfig
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import slick.driver.JdbcProfile

class UserDAO extends HasDatabaseConfig[JdbcProfile] {
  protected val dbConfig =  DatabaseConfigProvider.get[JdbcProfile](Play.current)

  import driver.api._

  def all(): Future[List[UserRow]] = db.run(Tables.User.result).map(_.toList)

  def findByEmail(email: String): Future[Option[UserRow]] = {
    db.run(Tables.User.filter(_.email === email).result.headOption)
  }

  def update(id: Int, newData: UserRow): Future[Int] = {
    db.run(Tables.User.filter(_.id === id).update(newData))
  }

  def delete(id: Int): Future[Int] = {
    db.run(Tables.User.filter(_.id === id).delete)
  }

}

The code generates the following compilation error:

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

I am using slick.driver.MySQLDriver$ / com.mysql.jdbc.Driver in the application.conf, and the models.Tables.scala file is automatically generated by slick-codegen lib.

Can anyone help me to fix this? Thanks!

Carlos Souza
  • 351
  • 6
  • 13
  • possible duplicate of [Scala Slick delete not working](http://stackoverflow.com/questions/24000759/scala-slick-delete-not-working) – Peanut May 29 '15 at 11:09
  • I saw this answer, and could not relate it to my problem, as Slick 3.0 is very different than Slick 2.1 – Carlos Souza May 29 '15 at 12:02

2 Answers2

7

Try importing a more specific API, so instead of import driver.api._ use import slick.driver.MySQLDriver.api._.

I just had the same issue and found this bug report for slick: https://github.com/playframework/play-slick/issues/249

Rajish
  • 6,755
  • 4
  • 34
  • 51
Mirko Stocker
  • 2,232
  • 16
  • 22
1

H2 Databases

If you're using H2 rather than MySQL, the below has fixed it for me with thanks to Carlos and Mirko here:

import slick.driver.H2Driver.api._ 

replacing the old:

import driver.api._

I hope delete support will get in the common API soon!

Rajish
  • 6,755
  • 4
  • 34
  • 51
bjfletcher
  • 11,168
  • 4
  • 52
  • 67