Skip to content

Commit

Permalink
feat: EXPOSED-258 Enhance upsert to allow exclusion of columns set on…
Browse files Browse the repository at this point in the history
… conflict

Edit documentation section to include new sample
  • Loading branch information
bog-walk committed Feb 22, 2024
1 parent d1161b6 commit 8b0dee3
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions documentation-website/Writerside/topics/Deep-Dive-into-DSL.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,26 @@ StarWarsFilms.upsert(
it[director] = "JJ Abrams"
}
```
If the update operation should be identical to the insert operation except for a few columns,
then `onUpdateExclude` should be provided an argument with the specific columns to exclude.
This parameter could also be used for the reverse case when only a small subset of columns should be updated but duplicating the insert values is tedious:
```kotlin
// on conflict, all columns EXCEPT [director] are updated with values from the lambda block
StarWarsFilms.upsert(onUpdateExclude = setOf(StarWarsFilms.director)) {
it[sequelId] = 9
it[name] = "The Rise of Skywalker"
it[director] = "JJ Abrams"
}

// on conflict, ONLY column [director] is updated with value from the lambda block
StarWarsFilms.upsert(
onUpdateExclude = StarWarsFilms.columns.toSet() - StarWarsFilms.director
) {
it[sequelId] = 9
it[name] = "The Rise of Skywalker"
it[director] = "JJ Abrams"
}
```
If a specific database supports user-defined key columns and none are provided, the table's primary key is used. If there
is no defined primary key, the first unique index is used. If there are no unique indices, each database handles this case
differently, so it is strongly advised that keys are defined to avoid unexpected results.
Expand Down

0 comments on commit 8b0dee3

Please sign in to comment.