Skip to content

Commit 16e09e9

Browse files
committed
🚑️(wayzer/user/ban) h2不支持returning
1 parent 910ba9b commit 16e09e9

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

scripts/wayzer/user/ban.dao.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package wayzer.user
22

33
import org.jetbrains.exposed.dao.id.IntIdTable
44
import org.jetbrains.exposed.sql.*
5+
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
56
import org.jetbrains.exposed.sql.javatime.CurrentTimestamp
67
import org.jetbrains.exposed.sql.javatime.timestamp
78
import org.jetbrains.exposed.sql.transactions.transaction
@@ -35,14 +36,19 @@ data class PlayerBan(
3536
}
3637

3738
companion object {
39+
private fun getById(id: Int) = transaction {
40+
T.selectAll().where { T.id eq id }.firstOrNull()?.let { PlayerBan(it) }
41+
}
42+
3843
fun create(ids: PlayerData, time: Duration, reason: String, operator: String?): PlayerBan = transaction {
39-
val ban = T.insertReturning {
44+
T.insertAndGetId {
4045
it[T.ids] = ids.idsInDB
4146
it[T.endTime] = Instant.now() + time
4247
it[T.operator] = operator
4348
it[T.reason] = reason
49+
}.let {
50+
getById(it.value)!!
4451
}
45-
PlayerBan(ban.first())
4652
}
4753

4854
fun allNotEnd() = transaction {
@@ -56,8 +62,9 @@ data class PlayerBan(
5662
}
5763

5864
fun delete(id: Int): PlayerBan? = transaction {
59-
T.deleteReturning { T.id eq id }.firstOrNull()
60-
?.let { PlayerBan(it) }
65+
getById(id)?.also {
66+
T.deleteWhere { T.id eq id }
67+
}
6168
}
6269
}
6370
}

0 commit comments

Comments
 (0)