3.0.0-RC1 compiled inserts

163 views
Skip to first unread message

Jeff Knight

unread,
Mar 10, 2015, 2:24:29 PM3/10/15
to scala...@googlegroups.com
Looking at the docs for 3.0.0-RC1, it looks like inserts can be compiled now instead of caching their invokers http://slick.typesafe.com/doc/3.0.0-RC1/queries.html#compiled-queries. However, I'm having a hard time getting it to work. The return types from basic inserts wrapped in Compiled { } is always [Nothing]. Is there some syntax that I am missing?

  private def testFunction(id: Rep[Long]) = {
    TestTable += (id)
  }
  
  private val testCompiled = Compiled(testFunction _)

Jeff Knight

unread,
Mar 12, 2015, 2:18:17 PM3/12/15
to scala...@googlegroups.com
Bumping this. In Slick 2.10, I was able to cache the insertInvoker, how do I migrate to now using compiled inserts?

Stefan Zeiger

unread,
Mar 12, 2015, 2:35:29 PM3/12/15
to scala...@googlegroups.com
`+=` gives you the DBIO action. You need to compile the query itself:

val c = Compiled(TestTable)
c += id


--
Stefan Zeiger
Slick Tech Lead
Typesafe - Build Reactive Apps!
Twitter: @StefanZeiger

Jeff Knight

unread,
Mar 16, 2015, 3:39:03 PM3/16/15
to scala...@googlegroups.com
Could you expand on this a little bit more? In your above example, it looks like you are just running Compile on the Table. What about an insert that uses the "map...returning...into" syntax?"

Naftoli Gugenheim

unread,
Mar 16, 2015, 5:06:58 PM3/16/15
to scala...@googlegroups.com

It's not a Table, it's a TableQuery, which <: Query. When you call map you get back a different Query. On the other hand returning is specific to inserting, I think it's part of the InsertInvoker api.


--

---
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/573d2aa0-df3b-4ed9-9413-14e36825609b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stefan Zeiger

unread,
Mar 17, 2015, 12:38:09 AM3/17/15
to scala...@googlegroups.com
On 2015-03-16 12:39, Jeff Knight wrote:
Could you expand on this a little bit more? In your above example, it looks like you are just running Compile on the Table. What about an insert that uses the "map...returning...into" syntax?"

You only compile the base query to insert into. The "returning" query is not run through the standard query compiler but processed in a much simpler and faster way, which is why we don't currently offer an API to cache this. It also doesn't affect the generated SQL statement.

Jeff

unread,
Apr 16, 2015, 11:28:43 PM4/16/15
to scala...@googlegroups.com
Coming back to this, the following throws an exception at runtime. 

private val compiledUserOrg = Compiled(UserOrg.map(_.userId))

Why would Compiled(UserOrg) work, but not Compiled(UserOrg.map(_.userId)), as both return queries?

Jeff

Naftoli Gugenheim

unread,
Apr 17, 2015, 12:30:54 AM4/17/15
to scala...@googlegroups.com

What is the exception?


--

---
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.
Message has been deleted

Matan Safriel

unread,
Apr 19, 2015, 8:09:50 PM4/19/15
to scala...@googlegroups.com
Hi,

I have bumped into this too, and frankly I fail to fathom the mechanics of it. I'm not sure I fathom how the two parts of this operation may or may not (?) each benefit from Slick compilation. It has been written that the insert itself cannot be compiled, which I find confounding since that is a parameterized database action.

Something more authoritative would surely help here, or in the documentation.

TIA,

Matan

Jeff

unread,
Apr 23, 2015, 5:47:07 PM4/23/15
to scala...@googlegroups.com
Here is the exception (with some class names redacted)

[error] (run-main-0) java.lang.AbstractMethodError: xxx.db.Boot$$anon$3.xxx$db$models$UserModel$_setter_$xxx$db$models$UserModel$$compiledIdTieBreaker_$eq(Lslick/lifted/CompiledStreamingExecutable;)V
java.lang.AbstractMethodError: xxx.db.Boot$$anon$3.xxx$db$models$UserModel$_setter_$xxx$db$models$UserModel$$compiledIdTieBreaker_$eq(Lslick/lifted/CompiledStreamingExecutable;)V
at xxx.db.models.UserModel$class.$init$(UserModel.scala:18)
at xxx.db.Boot$$anon$3.<init>(Boot.scala:14)
at xxx.db.Boot$.delayedEndpoint$xxx$db$Boot$1(Boot.scala:14)
at xxx.db.Boot$delayedInit$body.apply(Boot.scala:8)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.App$$anonfun$main$1.apply(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:381)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:35)
at scala.App$class.main(App.scala:76)
at xxx.db.Boot$.main(Boot.scala:8)
at xxx.db.Boot.main(Boot.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
[trace] Stack trace suppressed: run last db/compile:run for the full output.
java.lang.RuntimeException: Nonzero exit code: 1
at scala.sys.package$.error(package.scala:27)
[trace] Stack trace suppressed: run last db/compile:run for the full output.
[error] (db/compile:run) Nonzero exit code: 1
[error] Total time: 6 s, completed Apr 23, 2015 9:43:02 PM

Thanks
Jeff

Jeff

unread,
May 6, 2015, 10:53:00 PM5/6/15
to scala...@googlegroups.com
bumping for visibility

Jeff

unread,
May 7, 2015, 8:13:58 PM5/7/15
to scala...@googlegroups.com
Following up on this to see if anybody can shed any light. My understanding is that since this is a Query, it should be able to compile.

Thanks
Jeff

On Thursday, April 23, 2015 at 2:47:07 PM UTC-7, Jeff wrote:
Reply all
Reply to author
Forward
0 new messages