scala slick 2.1.0 delete query not working

64 views
Skip to first unread message

Prayag Upd

unread,
Oct 20, 2016, 1:26:16 AM10/20/16
to Slick / ScalaQuery
Scala Slick 2.1.0 documentation says the delete query is
val affectedRowsCount = query.delete
val invoker = query.deleteInvoker
val statement = query.deleteStatement


Also, 3.0.0
val query = coffees.filter(_.supID === 15)
val action = query.delete
val affectedRowsCount: Future[Int] = db.run(action) val sql = action.statements.head


But in my case, I'm using 2.1.0 and I get the compilation error .delete, as I don't see any such method in scala.slick.lifted.Query.scala.



I see .drop, 

/** Select all elements except the first `num` ones. */
def drop(num: Int): Query[E, U, C] = drop(num.toLong)

but it does not seem to work, 

val q = MarketplacesQuery.filter(_.id > 0l)
q.drop(10)

Any ideas?? I am using Slick 2.1.0.


Richard Dallaway

unread,
Oct 20, 2016, 6:22:04 AM10/20/16
to Slick / ScalaQuery
Hi - I’m not sure what’s going on for you there.  In case it helps you figure this out, there’s a simple runnable Slick 2.1 project with a delete in this repository: https://github.com/underscoreio/essential-slick-code/blob/2.1/chapter-03/src/main/scala/chapter03/main.scala#L57

(NB: if you want to clone that to work with it, the code is in a branch called 2.1)

Hope that helps you make some progress
Richard

--

---
You received this message because you are subscribed to the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaquery+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/7c897359-fcdb-43ee-aff3-47d8149804b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Prayag Upd

unread,
Oct 24, 2016, 9:55:49 PM10/24/16
to Slick / ScalaQuery
Something strange going on. I can write delete query on prod code, but not on the tests.

"returns a list of marketplaces" in new WithApplication() {

//given
Database.forURL(url = connectionUrl, driver = mysqlDriver) withSession { implicit session =>

var deleteall = MarketplacesQuery.filter(_.id > 0l).
delete // does not work

MarketplacesQuery.map(m => (m.name, m.email, m.contact))
.insert((
"some recording label", "some email", "some contact")) //works
}

//when
val actualResultFuture: Future[SimpleResult] = controllers.MarketplaceController.list()(FakeRequest())

//then
actualResultFuture.map(asyncResult => {
asyncResult.header.status must equalTo(
OK)
asyncResult.header.headers(
"Content-Type") must equalTo("application/json")
})
}

Dependencies I'm using are 

import play.Project._

name := "zyx-backend"

version := "1.0"

scalaVersion := "2.10.4"

playScalaSettings

resolvers += "Artima Maven Repository" at "http://repo.artima.com/releases"

libraryDependencies ++= Seq(
jdbc,
"com.google.zxing" % "core" % "2.0",
"mysql" % "mysql-connector-java" % "5.1.36",
"com.typesafe.slick" %% "slick" % "2.1.0",
"com.typesafe.play" %% "play-slick" % "0.6.1",
"org.slf4j" % "slf4j-nop" % "1.6.4",
"com.cloudphysics" % "jerkson_2.10" % "0.6.3",
"org.scalactic" %% "scalactic" % "3.0.0",
"org.scalatest" %% "scalatest" % "3.0.0" % "test"
)


Here's  dependency graph -> https://gist.github.com/prayagupd/7307203#gistcomment-1905351, graph shows for some reason application is using slick 2.0.2 instead of 2.1.0.

Prayag Upd

unread,
Oct 25, 2016, 1:31:08 AM10/25/16
to Slick / ScalaQuery
Well, this import worked, 


import play.api.db.slick.Config.driver.simple._


When I ctrl+clicked, It navigates to DeleteInvoker, which is actually in package scala.slick.driver

class DeleteInvoker(protected val tree: Node, param: Any) {
protected[this] val ResultSetMapping(_, CompiledStatement(_, sres: SQLBuilder.Result, _), _) = tree

def deleteStatement = sres.sql

def delete(implicit session: Backend#Session): Int = session.withPreparedStatement(deleteStatement) { st =>
sres.setter(st, 1, param)
st.executeUpdate
}

def deleteInvoker: this.type = this
}


I dont know how's play.api.db.slick.Config.driver.simple._ mapped to package scala.slick.driver

Reply all
Reply to author
Forward
0 new messages