Where in the Slick 3 documentation is it documented on how to do an insertOrUpdate
-like operation?
Asked
Active
Viewed 4,550 times
9

bjfletcher
- 11,168
- 4
- 52
- 67
-
1You mean something like [this code](https://github.com/slick/slick/blob/3.0.0/slick-testkit/src/main/scala/com/typesafe/slick/testkit/tests/InsertTest.scala#L131)? (From [this answer](http://stackoverflow.com/a/18985147).) BTW: asking for external resources is off-topic on SO. – Gábor Bakos Jun 04 '15 at 20:42
-
@GáborBakos It'd be nice to have that documented in http://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. :) – bjfletcher Jun 04 '15 at 21:04
-
1I think you can submit an issue to their tracker, probably referencing [issue 6](https://github.com/slick/slick/issues/6) to fix the missing documentation problem (unless you find an issue with that topic). The off-site resource thing is on http://stackoverflow.com/help/on-topic, point 4. – Gábor Bakos Jun 04 '15 at 21:10
-
1Question is valid, just reformulate it as "how to do insertOrUpdate in Slick 3?" – Ciantic Jul 08 '15 at 11:49
3 Answers
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.

Jethro
- 3,029
- 3
- 27
- 56
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>)

Som Bhattacharyya
- 3,972
- 35
- 54