4
votes

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.

2
Please show your Slick imports. There is probably something wrong with them. And yes, Slick's advanced usage of implicit can unfortunately mind-bending for newbies. Hopefully the direct embedding will offer a way out of that, when we find the time to develop it into a usable alternative (or replacement) for the lifted embedding (the standard api).cvogt
FYI: The doc says TableQuery's ddl method as an abbreviation. It actually is an extension method found via an implicit.cvogt
@cvogt Yeah you might be right, but I don't know which one to import though. Right now the only slick-related thing I'm importing is import play.api.db.slick.Profilewindweller
I'll investigate it. Maybe the play-slick example should be improved.cvogt
@cvogt Thank you! I agree!windweller

2 Answers

3
votes

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.

1
votes

slick 0.8.1 and slick 2.1.0 and I had the same Issue.

The reason why delete is not available on the Query is cause the play-slick Query does not contain a equivalent method of the delete method from slick Query.

I solved this Problem by changing to the original slick Driver

//import play.api.db.slick.Config.driver.simple._ //play-slick extensional Driver
import slick.driver.PostgresDriver.simple._       //original slick Driver