https://github.com/lukasforst/exposed-upsert
PostgreSQL upsert for Exposed framework.
https://github.com/lukasforst/exposed-upsert
exposed kotlin postgresql-upsert
Last synced: 11 months ago
JSON representation
PostgreSQL upsert for Exposed framework.
- Host: GitHub
- URL: https://github.com/lukasforst/exposed-upsert
- Owner: LukasForst
- License: mit
- Created: 2020-03-07T17:43:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-05-29T09:01:11.000Z (about 3 years ago)
- Last Synced: 2025-04-08T02:22:07.756Z (about 1 year ago)
- Topics: exposed, kotlin, postgresql-upsert
- Language: Kotlin
- Homepage: https://exposed.forst.dev
- Size: 719 KB
- Stars: 28
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Exposed PostgreSQL Upsert
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).
Usage can be seen for example in [Wire 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
}
```
Library is hosted on Maven Central.
```xml
dev.forst
exposed-upsert
1.3.4
```
Gradle:
```kotlin
implementation("dev.forst", "exposed-upsert", "1.3.4")
```