9
votes

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

3
You mean something like this code? (From this answer.) BTW: asking for external resources is off-topic on SO.Gábor Bakos
@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. :)bjfletcher
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.Gábor Bakos
Question is valid, just reformulate it as "how to do insertOrUpdate in Slick 3?"Ciantic

3 Answers

2
votes

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>)
2
votes

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.

0
votes

SimpleInsertActionComposer contains method required: doc link