Hi Josh,
always compose in Query when possible, which means single SQL query. If
not possible compose in DBIO, which means single connection. If not
possible compose in Future, which means multiple connections (but
potential re-use by your pool).
Chris
On 14.04.15 13:32, Josh wrote:
> Thanks Stefan, that works well.
>
> Can you give any general advice about when to compose in Future vs in DBIO?
> Should you always compose in DBIO where possible, or only when you need
> to do joins or perform operations in a single transaction or
> withPinnedSession?
> Are there situations when you should compose in Future instead?
>
> On Tuesday, April 14, 2015 at 9:32:57 AM UTC+1, Stefan Zeiger wrote:
>
> On 2015-04-13 17:28, Josh wrote:
>> valqueryResult = for {
>> userId <- db.run((users returning users.map(_.userId)) += user)
>> dogId <- db.run((dogs returning dogs.map(_.dogId)) += dog.copy(ownerId = Some(userId))
>> } yield userId
>>
>> Is it possible to do this transactionally, so that e.g. if the dog update fails, the user update will be rolled back?
>
> Compose the calls in DBIO, not in Future:
>
> val queryResult = db.run((for {
> userId <- (users returning users.map(_.userId)) += user
> dogId <- (dogs returning dogs.map(_.dogId)) += dog.copy(ownerId =
> Some(userId)
> } yield userId).transactionally)
>
> --
> Stefan Zeiger
> /Slick <
http://slick.typesafe.com> Tech Lead/
> Typesafe <
http://typesafe.com> - Build Reactive Apps!
> Twitter: @StefanZeiger <
http://twitter.com/#%21/StefanZeiger>
>
> --
>
> ---
> 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
> <mailto:
scalaquery+...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/scalaquery/94ddf7a0-099f-4262-ae80-b41af59eb88f%40googlegroups.com
> <
https://groups.google.com/d/msgid/scalaquery/94ddf7a0-099f-4262-ae80-b41af59eb88f%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit
https://groups.google.com/d/optout.