Here is how we get the id of the added row (source):
val munichId = Cities.insert {
it[name] = "Munich"
} get Cities.id
What about getting the whole row? I use map
for select
operations but it does not work for insert
.
Here is how we get the id of the added row (source):
val munichId = Cities.insert {
it[name] = "Munich"
} get Cities.id
What about getting the whole row? I use map
for select
operations but it does not work for insert
.
val row = Cities.insert {
it[name] = "Munich"
}.resultedValues!!.first()
Another option is insertReturning
method from https://github.com/JetBrains/Exposed/pull/2060
Items.insertReturning(listOf(Items.id, Items.name)) {
it[name] = "B"
it[price] = 200.0
}.map {
it[Items.id].value to it[Items.name]
}
© 2022 - 2024 — McMap. All rights reserved.