Search code examples
slickplay-slick

Can't access delete method on Slick query


This is very very very frustrating. I have been trying to pick up Slick for a while, and obstacles just keep coming. The concept of Slick is really awesome, but it is very difficult to learn, and unlike Scala, it doesn't have "beginner", "intermediate", and "advanced" style where people in all stages can use it easily.

I'm using Play-Slick (Slick 2.0.0) https://github.com/freekh/play-slick, following its Multi-DB cake example: https://github.com/freekh/play-slick/tree/master/samples/play-slick-cake-sample/app

For some reason, first, ddl does not belong to TableQuery, unlike the claim in the document: "The TableQuery‘s ddl method creates DDL". This shows through the scaladoc: http://slick.typesafe.com/doc/2.0.0/api/#scala.slick.lifted.TableQuery There is no ddl method there.

Second, my slick.lifted.Query can't generate delete method. It works fine with list, but not with delete.

val S3Files = TableQuery[S3Files]
S3Files.where(_.url === url).delete

This wouldn't work...then I tried:

val query = (for(s <- S3Files if s.url === url) yield s)
query.list  //this works
query.delete //ehh?? can't find the method

val query2 = (for(s <- S3Files if s.url === url))
query2.delete //still won't work

Well...since Slick uses a very complicated (at least to newbies) implicit type conversion system, I don't really know what went wrong.


Solution

  • I tried it by simply adding

    Cats.ddl.create
    Cats.filter(_.name===cat.name).delete
    

    to play-slick-cake-sample/app/controllers/Application.scala. Works fine for me.

    Looks like you are using the wrong imports. Look at https://github.com/freekh/play-slick/blob/master/samples/play-slick-sample/app/controllers/Application.scala and mimic the imports.