Can't access delete method on Slick query

只愿长相守 提交于 2019-12-10 18:15:06

问题


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.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/22288836/cant-access-delete-method-on-slick-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!