Getting back rows affected (Int) in Slick 3.0

281 views
Skip to first unread message

Levi Notik

unread,
May 15, 2015, 2:25:44 PM5/15/15
to scala...@googlegroups.com
In previous versions of Slick, there was insert function defined on a TableQuery that returned an insertion result. I'm migrating to the new API and doing something like:

DBIO.seq(someTable += someValue)

but this has type 

dbio.DBIOAction[Unit, NoStream, Write]


How can I get back the rows affected?

Levi Notik

unread,
May 15, 2015, 2:56:36 PM5/15/15
to scala...@googlegroups.com
The problem here seems to be that the types aren't lining up the way I would expect them to. Here's what Scala sees the types as:

 
  val q: PostgresDriver.DriverAction[PostgresDriver.InsertActionExtensionMethods[(String, String)]#SingleInsertResult, NoStream, Write] = Admins.tableQuery += ((username, grantor))
  val seq
: dbio.DBIOAction[Unit, NoStream, Write] = DBIO.seq(q)
 
db.run(seq)



This doesn't make sense to me. If `q` has type `DriverAction[PostgresDriver.InsertActionExtensionMethods[(String, String)]#SingleInsertResult...` where SingleInsertResult is a type alias to `Int` then shouldn't my `DBIO.seq` return a `DBIOAction[Int, NoStream, Write]`?

Aldo Stracquadanio

unread,
May 16, 2015, 10:52:25 AM5/16/15
to scala...@googlegroups.com
I believe that your problem is that you are using DBIO.seq and when combining different DBIO action in that way the result will be a Unit.

Stefan Ollinger

unread,
May 16, 2015, 11:01:35 AM5/16/15
to scala...@googlegroups.com
You can try DBIO.sequence or DBIO.fold instead of DBIO.seq.
--

---
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/15f152fb-c11f-4476-8919-d6dcd86867cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Naftoli Gugenheim

unread,
May 17, 2015, 6:43:36 PM5/17/15
to scala...@googlegroups.com

Why are you using DBIO.seq? IIRC it always returns Unit, that's part of its purpose.


--

---
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.
Reply all
Reply to author
Forward
0 new messages