insertOrUpdate with Slick 3
Asked Answered
T

3

9

Where in the Slick 3 documentation is it documented on how to do an insertOrUpdate-like operation?

Terriss answered 4/6, 2015 at 20:0 Comment(4)
You mean something like this code? (From this answer.) BTW: asking for external resources is off-topic on SO.Heartwhole
@GáborBakos It'd be nice to have that documented in slick.typesafe.com/doc/3.0.0. Surprised there appears to be nothing about insertOrUpdate. Thanks for the BTW. :) If you don't mind, where can I read about this rule? I'd like to become a better SO citizen. :)Terriss
I think you can submit an issue to their tracker, probably referencing issue 6 to fix the missing documentation problem (unless you find an issue with that topic). The off-site resource thing is on stackoverflow.com/help/on-topic, point 4.Heartwhole
Question is valid, just reformulate it as "how to do insertOrUpdate in Slick 3?"Nayarit
I
3

The insertOrUpdate method that comes with slick 3.x is limited to MySQL Only. You won't get any warnings/code documentation, it will just throw Integrity exceptions.

In order to upsert with Slick if using Postgres, you can use slick-pg.

Inbound answered 2/1, 2020 at 12:32 Comment(0)
S
2

This support is there in Slick . Look at this merge : Pull Request Merged Here The support was added in Slick 2.1 . These are also called upsert statements.

However i would think you would want to use plain SQL(for the native DB you are using) for this kind of requirement. Look here for examples of how to use Slick to do this.

Basically code that looks like the following ,

val reviews = TableQuery[<Class extending Table>]
val upsert: DBIO[Int] = reviews.insertOrUpdate(<value to be inserted>)
Skees answered 4/4, 2016 at 17:4 Comment(0)
N
0

SimpleInsertActionComposer contains method required: doc link

Neurasthenic answered 23/5, 2016 at 14:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.