mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-18 14:47:15 +00:00
commit
89b40a0f5c
@ -1,5 +1,14 @@
|
||||
# Changelog
|
||||
|
||||
## 0.9.7
|
||||
|
||||
* `Repos`:
|
||||
* `Exposed`:
|
||||
* Fix in `ExposedOneToManyKeyValueRepo` - now it will not use `insertIgnore`
|
||||
* `Ktor`:
|
||||
* `Server`:
|
||||
* `Route#includeWebsocketHandling` now will check that `WebSockets` feature and install it if not
|
||||
|
||||
## 0.9.6
|
||||
|
||||
* `Repos`:
|
||||
|
@ -45,5 +45,5 @@ dokka_version=1.6.10
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.9.6
|
||||
android_code_version=96
|
||||
version=0.9.7
|
||||
android_code_version=97
|
||||
|
@ -2,25 +2,23 @@ package dev.inmo.micro_utils.ktor.server
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.safely
|
||||
import dev.inmo.micro_utils.ktor.common.*
|
||||
import io.ktor.application.featureOrNull
|
||||
import io.ktor.application.install
|
||||
import io.ktor.http.cio.websocket.*
|
||||
import io.ktor.routing.Route
|
||||
import io.ktor.routing.application
|
||||
import io.ktor.websocket.webSocket
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.serialization.SerializationStrategy
|
||||
|
||||
private suspend fun DefaultWebSocketSession.checkReceivedAndCloseIfExists() {
|
||||
if (incoming.tryReceive() != null) {
|
||||
close()
|
||||
throw CorrectCloseException
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> Route.includeWebsocketHandling(
|
||||
suburl: String,
|
||||
flow: Flow<T>,
|
||||
converter: (T) -> StandardKtorSerialInputData
|
||||
) {
|
||||
application.apply {
|
||||
featureOrNull(io.ktor.websocket.WebSockets) ?: install(io.ktor.websocket.WebSockets)
|
||||
}
|
||||
webSocket(suburl) {
|
||||
safely {
|
||||
flow.collect {
|
||||
|
@ -35,10 +35,15 @@ open class ExposedOneToManyKeyValueRepo<Key, Value>(
|
||||
if (select { keyColumn.eq(k).and(valueColumn.eq(v)) }.limit(1).count() > 0) {
|
||||
return@mapNotNull null
|
||||
}
|
||||
insertIgnore {
|
||||
val insertResult = insert {
|
||||
it[keyColumn] = k
|
||||
it[valueColumn] = v
|
||||
}.getOrNull(keyColumn) ?.let { k to v }
|
||||
}
|
||||
if (insertResult.insertedCount > 0) {
|
||||
k to v
|
||||
} else {
|
||||
null
|
||||
}
|
||||
} ?: emptyList()
|
||||
}
|
||||
}.forEach { _onNewValue.emit(it) }
|
||||
|
Loading…
Reference in New Issue
Block a user