使用Slick 3插入OrUpdate

时间:2015-06-04 20:00:55

标签: scala slick slick-3.0

在Slick 3 documentation中的哪个部分记录了如何进行insertOrUpdate式操作?

3 个答案:

答案 0 :(得分:2)

slick 3.x随附的insertOrUpdate方法为limited to MySQL Only。您将不会获得任何警告/代码文档,它只会引发Integrity异常。

要在使用Postgres的情况下使用Slick进行增补,可以使用slick-pg

答案 1 :(得分:1)

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 :(得分:0)

SimpleInsertActionComposer包含所需方法:doc link