Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

insertOrUpdate with Slick 3

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

like image 644
bjfletcher Avatar asked Jun 04 '15 20:06

bjfletcher


2 Answers

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.

like image 126
Jethro Avatar answered Nov 11 '22 00:11

Jethro


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>)
like image 36
Som Bhattacharyya Avatar answered Nov 11 '22 02:11

Som Bhattacharyya