-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d91b173
commit 0358f33
Showing
1 changed file
with
18 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,21 @@ | ||
# exposed-upsert | ||
# Exposed PostgreSQL Upsert | ||
![CI Build Pipeline](https://github.com/LukasForst/exposed-upsert/workflows/CI%20Build%20Pipeline/badge.svg) | ||
|
||
PostgreSQL upsert for Exposed framework based on issues. | ||
Unfortunately, current [Exposed](https://github.com/JetBrains/Exposed) framework does not contain upsert | ||
(update or insert) functionality out of the box. | ||
This simple extension library provides implementation for PostgreSQL. | ||
Implementation is based on the comment [Maxr1998](https://github.com/Maxr1998) made | ||
[here](https://github.com/JetBrains/Exposed/issues/167#issuecomment-480199613). | ||
|
||
Implementation based on https://github.com/JetBrains/Exposed/issues/167#issuecomment-480199613 | ||
Usage can be seen for example in [Wire](https://github.com/wireapp/) [Poll Bot](https://github.com/wireapp/poll-bot) | ||
[here](https://github.com/wireapp/poll-bot/blob/fc74e2ae15691484714efe2b7803dbc5e235da01/src/main/kotlin/com/wire/bots/polls/dao/PollRepository.kt#L49) | ||
|
||
Following code tries to insert new value of `optionId` to `Votes` table where `pollId` and `userId` is composite key. | ||
If the combination `pollId` and `userId` already exist, `optionId` is updated. | ||
```kotlin | ||
Votes.insertOrUpdate(Votes.pollId, Votes.userId) { | ||
it[pollId] = pollAction.pollId | ||
it[pollOption] = pollAction.optionId | ||
it[userId] = pollAction.userId | ||
} | ||
``` |