mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2025-09-18 06:49:20 +00:00
Compare commits
40 Commits
Author | SHA1 | Date | |
---|---|---|---|
58d754bbde | |||
8f25c123dd | |||
76e214fc08 | |||
2b5380f8d6 | |||
844a129094 | |||
a3090cca9d | |||
b7b5159e9c | |||
0f8bc2c950 | |||
69f5c49f45 | |||
9b308e6fb8 | |||
3e3f91128b | |||
0d1aae0ef7 | |||
4d022f0480 | |||
153e20d00e | |||
a9a8171dd6 | |||
bf5c3b59b2 | |||
607c432bdb | |||
ae5c010770 | |||
d5e432437f | |||
9f99ebce01 | |||
64ee899b84 | |||
e0e0c1658b | |||
2c586f667c | |||
64164ef6c1 | |||
22343c0731 | |||
f4ec1a4c60 | |||
c1c33cceb1 | |||
a3e975b2ba | |||
06e705a687 | |||
d56eb6c867 | |||
9cbca864e3 | |||
abb4378694 | |||
0eb698d9a4 | |||
15ea9f2093 | |||
d47aca0923 | |||
1ac50e9959 | |||
6adfbe3a96 | |||
59f36e62e9 | |||
54af116009 | |||
38fbec8e3b |
14
.github/workflows/build.yml
vendored
14
.github/workflows/build.yml
vendored
@@ -9,9 +9,6 @@ jobs:
|
|||||||
- uses: actions/setup-java@v1
|
- uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: 11
|
java-version: 11
|
||||||
- name: Fix android 32.0.0 dx
|
|
||||||
continue-on-error: true
|
|
||||||
run: cd /usr/local/lib/android/sdk/build-tools/32.0.0/ && mv d8 dx && cd lib && mv d8.jar dx.jar
|
|
||||||
- name: Rewrite version
|
- name: Rewrite version
|
||||||
run: |
|
run: |
|
||||||
branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`"
|
branch="`echo "${{ github.ref }}" | grep -o "[^/]*$"`"
|
||||||
@@ -20,9 +17,8 @@ jobs:
|
|||||||
mv gradle.properties.tmp gradle.properties
|
mv gradle.properties.tmp gradle.properties
|
||||||
- name: Build
|
- name: Build
|
||||||
run: ./gradlew build
|
run: ./gradlew build
|
||||||
# - name: Publish
|
- name: Publish
|
||||||
# continue-on-error: true
|
continue-on-error: true
|
||||||
# run: ./gradlew --no-parallel publishAllPublicationsToGithubPackagesRepository
|
run: ./gradlew publishAllPublicationsToGiteaRepository
|
||||||
# env:
|
env:
|
||||||
# GITHUBPACKAGES_USER: ${{ github.actor }}
|
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||||
# GITHUBPACKAGES_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
@@ -1,8 +0,0 @@
|
|||||||
job("Build and run tests") {
|
|
||||||
container(displayName = "Run gradle build", image = "openjdk:11") {
|
|
||||||
kotlinScript { api ->
|
|
||||||
// here can be your complex logic
|
|
||||||
api.gradlew("build")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
39
CHANGELOG.md
39
CHANGELOG.md
@@ -1,5 +1,44 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.14.3
|
||||||
|
|
||||||
|
* `Common`:
|
||||||
|
* New type `Progress`
|
||||||
|
* `Ktor`:
|
||||||
|
* `Client`:
|
||||||
|
* New universal `uniUpload` extension for `HttpClient`
|
||||||
|
* `Server`:
|
||||||
|
* New universal `handleUniUpload` extension for `ApplicationCall`
|
||||||
|
* Add extensions `download` and `downloadToTemporalFile`
|
||||||
|
|
||||||
|
## 0.14.2
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `Exposed`: `0.40.1` -> `0.41.1`
|
||||||
|
|
||||||
|
|
||||||
|
## 0.14.1
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `Klock`: `3.3.1` -> `3.4.0`
|
||||||
|
* `UUID`: `0.5.0` -> `0.6.0`
|
||||||
|
|
||||||
|
## 0.14.0
|
||||||
|
|
||||||
|
**ALL DEPRECATIONS HAVE BEEN REMOVED**
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `Kotlin`: `1.7.10` -> `1.7.20`
|
||||||
|
* `Klock`: `3.3.0` -> `3.3.1`
|
||||||
|
* `Compose`: `1.2.0` -> `1.2.1`
|
||||||
|
* `Exposed`: `0.39.2` -> `0.40.1`
|
||||||
|
|
||||||
|
## 0.13.2
|
||||||
|
|
||||||
|
* `Versions`:
|
||||||
|
* `Klock`: `3.1.0` -> `3.3.0`
|
||||||
|
* `Ktor`: `2.1.2` -> `2.1.3`
|
||||||
|
|
||||||
## 0.13.1
|
## 0.13.1
|
||||||
|
|
||||||
* `Repos`:
|
* `Repos`:
|
||||||
|
@@ -0,0 +1,37 @@
|
|||||||
|
package dev.inmo.micro_utils.common
|
||||||
|
|
||||||
|
import kotlinx.serialization.Serializable
|
||||||
|
import kotlin.jvm.JvmInline
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
@JvmInline
|
||||||
|
value class Progress private constructor(
|
||||||
|
val of1: Double
|
||||||
|
) {
|
||||||
|
val of1Float
|
||||||
|
get() = of1.toFloat()
|
||||||
|
val of100
|
||||||
|
get() = of1 * 100
|
||||||
|
val of100Float
|
||||||
|
get() = of100.toFloat()
|
||||||
|
val of100Int
|
||||||
|
get() = of100.toInt()
|
||||||
|
|
||||||
|
init {
|
||||||
|
require(of1 in rangeOfValues) {
|
||||||
|
"Progress main value should be in $rangeOfValues, but incoming value is $of1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val rangeOfValues = 0.0 .. 1.0
|
||||||
|
|
||||||
|
val START = Progress(rangeOfValues.start)
|
||||||
|
val COMPLETED = Progress(rangeOfValues.endInclusive)
|
||||||
|
|
||||||
|
operator fun invoke(of1: Double) = Progress(of1.coerceIn(rangeOfValues))
|
||||||
|
operator fun invoke(part: Number, total: Number) = Progress(
|
||||||
|
part.toDouble() / total.toDouble()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,80 @@
|
|||||||
|
@file:Suppress(
|
||||||
|
"RemoveRedundantCallsOfConversionMethods",
|
||||||
|
"RedundantVisibilityModifier",
|
||||||
|
)
|
||||||
|
|
||||||
|
package dev.inmo.micro_utils.common
|
||||||
|
|
||||||
|
import kotlin.Byte
|
||||||
|
import kotlin.Double
|
||||||
|
import kotlin.Float
|
||||||
|
import kotlin.Int
|
||||||
|
import kotlin.Long
|
||||||
|
import kotlin.Short
|
||||||
|
import kotlin.Suppress
|
||||||
|
|
||||||
|
public operator fun Progress.plus(other: Progress): Progress = Progress(of1 + other.of1)
|
||||||
|
|
||||||
|
public operator fun Progress.minus(other: Progress): Progress = Progress(of1 - other.of1)
|
||||||
|
|
||||||
|
public operator fun Progress.plus(i: Byte): Progress = Progress((of1 + i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.minus(i: Byte): Progress = Progress((of1 - i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.times(i: Byte): Progress = Progress((of1 * i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.div(i: Byte): Progress = Progress((of1 / i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.rem(i: Byte): Progress = Progress((of1 % i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.plus(i: Short): Progress = Progress((of1 + i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.minus(i: Short): Progress = Progress((of1 - i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.times(i: Short): Progress = Progress((of1 * i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.div(i: Short): Progress = Progress((of1 / i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.rem(i: Short): Progress = Progress((of1 % i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.plus(i: Int): Progress = Progress((of1 + i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.minus(i: Int): Progress = Progress((of1 - i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.times(i: Int): Progress = Progress((of1 * i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.div(i: Int): Progress = Progress((of1 / i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.rem(i: Int): Progress = Progress((of1 % i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.plus(i: Long): Progress = Progress((of1 + i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.minus(i: Long): Progress = Progress((of1 - i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.times(i: Long): Progress = Progress((of1 * i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.div(i: Long): Progress = Progress((of1 / i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.rem(i: Long): Progress = Progress((of1 % i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.plus(i: Float): Progress = Progress((of1 + i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.minus(i: Float): Progress = Progress((of1 - i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.times(i: Float): Progress = Progress((of1 * i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.div(i: Float): Progress = Progress((of1 / i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.rem(i: Float): Progress = Progress((of1 % i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.plus(i: Double): Progress = Progress((of1 + i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.minus(i: Double): Progress = Progress((of1 - i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.times(i: Double): Progress = Progress((of1 * i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.div(i: Double): Progress = Progress((of1 / i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.rem(i: Double): Progress = Progress((of1 % i).toDouble())
|
||||||
|
|
||||||
|
public operator fun Progress.compareTo(other: Progress): Int = (of1 - other.of1).toInt()
|
@@ -14,5 +14,5 @@ crypto_js_version=4.1.1
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.13.1
|
version=0.14.3
|
||||||
android_code_version=159
|
android_code_version=164
|
||||||
|
@@ -1,17 +1,17 @@
|
|||||||
[versions]
|
[versions]
|
||||||
|
|
||||||
kt = "1.7.10"
|
kt = "1.7.20"
|
||||||
kt-serialization = "1.4.0"
|
kt-serialization = "1.4.1"
|
||||||
kt-coroutines = "1.6.4"
|
kt-coroutines = "1.6.4"
|
||||||
|
|
||||||
jb-compose = "1.2.0-beta02"
|
jb-compose = "1.2.1"
|
||||||
jb-exposed = "0.39.2"
|
jb-exposed = "0.41.1"
|
||||||
jb-dokka = "1.7.10"
|
jb-dokka = "1.7.20"
|
||||||
|
|
||||||
klock = "3.1.0"
|
klock = "3.4.0"
|
||||||
uuid = "0.5.0"
|
uuid = "0.6.0"
|
||||||
|
|
||||||
ktor = "2.1.2"
|
ktor = "2.1.3"
|
||||||
|
|
||||||
gh-release = "2.4.1"
|
gh-release = "2.4.1"
|
||||||
|
|
||||||
|
@@ -15,5 +15,9 @@ kotlin {
|
|||||||
api libs.ktor.client
|
api libs.ktor.client
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
androidMain {
|
||||||
|
dependsOn jvmMain
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,3 @@
|
|||||||
|
package dev.inmo.micro_utils.ktor.client
|
||||||
|
|
||||||
|
typealias OnUploadCallback = suspend (uploaded: Long, count: Long) -> Unit
|
@@ -7,5 +7,5 @@ import io.ktor.client.HttpClient
|
|||||||
expect suspend fun HttpClient.tempUpload(
|
expect suspend fun HttpClient.tempUpload(
|
||||||
fullTempUploadDraftPath: String,
|
fullTempUploadDraftPath: String,
|
||||||
file: MPPFile,
|
file: MPPFile,
|
||||||
onUpload: (uploaded: Long, count: Long) -> Unit = { _, _ -> }
|
onUpload: OnUploadCallback = { _, _ -> }
|
||||||
): TemporalFileId
|
): TemporalFileId
|
||||||
|
@@ -0,0 +1,31 @@
|
|||||||
|
package dev.inmo.micro_utils.ktor.client
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.common.FileName
|
||||||
|
import dev.inmo.micro_utils.ktor.common.LambdaInputProvider
|
||||||
|
import io.ktor.client.HttpClient
|
||||||
|
import io.ktor.http.Headers
|
||||||
|
import kotlinx.serialization.DeserializationStrategy
|
||||||
|
import kotlinx.serialization.StringFormat
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
|
||||||
|
data class UniUploadFileInfo(
|
||||||
|
val fileName: FileName,
|
||||||
|
val mimeType: String,
|
||||||
|
val inputAllocator: LambdaInputProvider
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will execute submitting of multipart data request
|
||||||
|
*
|
||||||
|
* @param data [Map] where keys will be used as names for multipart parts and values as values. If you will pass
|
||||||
|
* [dev.inmo.micro_utils.common.MPPFile] (File from JS or JVM platform). Also you may pass [UniUploadFileInfo] as value
|
||||||
|
* in case you wish to pass other source of multipart binary data than regular file
|
||||||
|
*/
|
||||||
|
expect suspend fun <T> HttpClient.uniUpload(
|
||||||
|
url: String,
|
||||||
|
data: Map<String, Any>,
|
||||||
|
resultDeserializer: DeserializationStrategy<T>,
|
||||||
|
headers: Headers = Headers.Empty,
|
||||||
|
stringFormat: StringFormat = Json,
|
||||||
|
onUpload: OnUploadCallback = { _, _ -> }
|
||||||
|
): T?
|
@@ -1,6 +1,8 @@
|
|||||||
package dev.inmo.micro_utils.ktor.client
|
package dev.inmo.micro_utils.ktor.client
|
||||||
|
|
||||||
import dev.inmo.micro_utils.common.MPPFile
|
import dev.inmo.micro_utils.common.MPPFile
|
||||||
|
import dev.inmo.micro_utils.coroutines.LinkedSupervisorJob
|
||||||
|
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||||
import dev.inmo.micro_utils.ktor.common.TemporalFileId
|
import dev.inmo.micro_utils.ktor.common.TemporalFileId
|
||||||
import io.ktor.client.HttpClient
|
import io.ktor.client.HttpClient
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
@@ -12,10 +14,11 @@ import org.w3c.xhr.XMLHttpRequest.Companion.DONE
|
|||||||
suspend fun tempUpload(
|
suspend fun tempUpload(
|
||||||
fullTempUploadDraftPath: String,
|
fullTempUploadDraftPath: String,
|
||||||
file: MPPFile,
|
file: MPPFile,
|
||||||
onUpload: (Long, Long) -> Unit
|
onUpload: OnUploadCallback
|
||||||
): TemporalFileId {
|
): TemporalFileId {
|
||||||
val formData = FormData()
|
val formData = FormData()
|
||||||
val answer = CompletableDeferred<TemporalFileId>(currentCoroutineContext().job)
|
val answer = CompletableDeferred<TemporalFileId>(currentCoroutineContext().job)
|
||||||
|
val subscope = CoroutineScope(currentCoroutineContext().LinkedSupervisorJob())
|
||||||
|
|
||||||
formData.append(
|
formData.append(
|
||||||
"data",
|
"data",
|
||||||
@@ -25,7 +28,7 @@ suspend fun tempUpload(
|
|||||||
val request = XMLHttpRequest()
|
val request = XMLHttpRequest()
|
||||||
request.responseType = XMLHttpRequestResponseType.TEXT
|
request.responseType = XMLHttpRequestResponseType.TEXT
|
||||||
request.upload.onprogress = {
|
request.upload.onprogress = {
|
||||||
onUpload(it.loaded.toLong(), it.total.toLong())
|
subscope.launchSafelyWithoutExceptions { onUpload(it.loaded.toLong(), it.total.toLong()) }
|
||||||
}
|
}
|
||||||
request.onload = {
|
request.onload = {
|
||||||
if (request.status == 200.toShort()) {
|
if (request.status == 200.toShort()) {
|
||||||
@@ -48,12 +51,14 @@ suspend fun tempUpload(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return answer.await()
|
return answer.await().also {
|
||||||
|
subscope.cancel()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
actual suspend fun HttpClient.tempUpload(
|
actual suspend fun HttpClient.tempUpload(
|
||||||
fullTempUploadDraftPath: String,
|
fullTempUploadDraftPath: String,
|
||||||
file: MPPFile,
|
file: MPPFile,
|
||||||
onUpload: (uploaded: Long, count: Long) -> Unit
|
onUpload: OnUploadCallback
|
||||||
): TemporalFileId = dev.inmo.micro_utils.ktor.client.tempUpload(fullTempUploadDraftPath, file, onUpload)
|
): TemporalFileId = dev.inmo.micro_utils.ktor.client.tempUpload(fullTempUploadDraftPath, file, onUpload)
|
||||||
|
@@ -0,0 +1,96 @@
|
|||||||
|
package dev.inmo.micro_utils.ktor.client
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.common.MPPFile
|
||||||
|
import dev.inmo.micro_utils.common.Progress
|
||||||
|
import dev.inmo.micro_utils.coroutines.LinkedSupervisorJob
|
||||||
|
import dev.inmo.micro_utils.coroutines.launchSafelyWithoutExceptions
|
||||||
|
import io.ktor.client.HttpClient
|
||||||
|
import io.ktor.http.Headers
|
||||||
|
import io.ktor.utils.io.core.readBytes
|
||||||
|
import kotlinx.coroutines.CompletableDeferred
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.cancel
|
||||||
|
import kotlinx.coroutines.currentCoroutineContext
|
||||||
|
import kotlinx.coroutines.job
|
||||||
|
import kotlinx.serialization.DeserializationStrategy
|
||||||
|
import kotlinx.serialization.StringFormat
|
||||||
|
import kotlinx.serialization.encodeToString
|
||||||
|
import org.khronos.webgl.Int8Array
|
||||||
|
import org.w3c.files.Blob
|
||||||
|
import org.w3c.xhr.FormData
|
||||||
|
import org.w3c.xhr.TEXT
|
||||||
|
import org.w3c.xhr.XMLHttpRequest
|
||||||
|
import org.w3c.xhr.XMLHttpRequestResponseType
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will execute submitting of multipart data request
|
||||||
|
*
|
||||||
|
* @param data [Map] where keys will be used as names for multipart parts and values as values. If you will pass
|
||||||
|
* [dev.inmo.micro_utils.common.MPPFile] (File from JS or JVM platform). Also you may pass [UniUploadFileInfo] as value
|
||||||
|
* in case you wish to pass other source of multipart binary data than regular file
|
||||||
|
*/
|
||||||
|
actual suspend fun <T> HttpClient.uniUpload(
|
||||||
|
url: String,
|
||||||
|
data: Map<String, Any>,
|
||||||
|
resultDeserializer: DeserializationStrategy<T>,
|
||||||
|
headers: Headers,
|
||||||
|
stringFormat: StringFormat,
|
||||||
|
onUpload: OnUploadCallback
|
||||||
|
): T? {
|
||||||
|
val formData = FormData()
|
||||||
|
val answer = CompletableDeferred<T?>(currentCoroutineContext().job)
|
||||||
|
val subscope = CoroutineScope(currentCoroutineContext().LinkedSupervisorJob())
|
||||||
|
|
||||||
|
data.forEach { (k, v) ->
|
||||||
|
when (v) {
|
||||||
|
is MPPFile -> formData.append(
|
||||||
|
k,
|
||||||
|
v
|
||||||
|
)
|
||||||
|
is UniUploadFileInfo -> formData.append(
|
||||||
|
k,
|
||||||
|
Blob(arrayOf(Int8Array(v.inputAllocator().readBytes().toTypedArray()))),
|
||||||
|
v.fileName.name
|
||||||
|
)
|
||||||
|
else -> formData.append(
|
||||||
|
k,
|
||||||
|
stringFormat.encodeToString(v)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val request = XMLHttpRequest()
|
||||||
|
headers.forEach { s, strings ->
|
||||||
|
request.setRequestHeader(s, strings.joinToString())
|
||||||
|
}
|
||||||
|
request.responseType = XMLHttpRequestResponseType.TEXT
|
||||||
|
request.upload.onprogress = {
|
||||||
|
subscope.launchSafelyWithoutExceptions { onUpload(it.loaded.toLong(), it.total.toLong()) }
|
||||||
|
}
|
||||||
|
request.onload = {
|
||||||
|
if (request.status == 200.toShort()) {
|
||||||
|
answer.complete(
|
||||||
|
stringFormat.decodeFromString(resultDeserializer, request.responseText)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
answer.completeExceptionally(Exception("Something went wrong: $it"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
request.onerror = {
|
||||||
|
answer.completeExceptionally(Exception("Something went wrong: $it"))
|
||||||
|
}
|
||||||
|
request.open("POST", url, true)
|
||||||
|
request.send(formData)
|
||||||
|
|
||||||
|
answer.invokeOnCompletion {
|
||||||
|
runCatching {
|
||||||
|
if (request.readyState != XMLHttpRequest.DONE) {
|
||||||
|
request.abort()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return answer.await().also {
|
||||||
|
subscope.cancel()
|
||||||
|
}
|
||||||
|
}
|
@@ -4,6 +4,8 @@ import dev.inmo.micro_utils.common.MPPFile
|
|||||||
import io.ktor.client.request.forms.InputProvider
|
import io.ktor.client.request.forms.InputProvider
|
||||||
import io.ktor.utils.io.streams.asInput
|
import io.ktor.utils.io.streams.asInput
|
||||||
|
|
||||||
actual suspend fun MPPFile.inputProvider(): InputProvider = InputProvider(length()) {
|
fun MPPFile.inputProviderSync(): InputProvider = InputProvider(length()) {
|
||||||
inputStream().asInput()
|
inputStream().asInput()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
actual suspend fun MPPFile.inputProvider(): InputProvider = inputProviderSync()
|
||||||
|
@@ -18,7 +18,7 @@ internal val MPPFile.mimeType: String
|
|||||||
actual suspend fun HttpClient.tempUpload(
|
actual suspend fun HttpClient.tempUpload(
|
||||||
fullTempUploadDraftPath: String,
|
fullTempUploadDraftPath: String,
|
||||||
file: MPPFile,
|
file: MPPFile,
|
||||||
onUpload: (Long, Long) -> Unit
|
onUpload: OnUploadCallback
|
||||||
): TemporalFileId {
|
): TemporalFileId {
|
||||||
val inputProvider = file.inputProvider()
|
val inputProvider = file.inputProvider()
|
||||||
val fileId = submitFormWithBinaryData(
|
val fileId = submitFormWithBinaryData(
|
||||||
|
@@ -0,0 +1,101 @@
|
|||||||
|
package dev.inmo.micro_utils.ktor.client
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.common.Progress
|
||||||
|
import io.ktor.client.HttpClient
|
||||||
|
import io.ktor.client.engine.mergeHeaders
|
||||||
|
import io.ktor.client.plugins.onUpload
|
||||||
|
import io.ktor.client.request.HttpRequestBuilder
|
||||||
|
import io.ktor.client.request.forms.InputProvider
|
||||||
|
import io.ktor.client.request.forms.formData
|
||||||
|
import io.ktor.client.request.forms.submitForm
|
||||||
|
import io.ktor.client.request.forms.submitFormWithBinaryData
|
||||||
|
import io.ktor.client.request.headers
|
||||||
|
import io.ktor.client.statement.bodyAsText
|
||||||
|
import io.ktor.http.Headers
|
||||||
|
import io.ktor.http.HttpHeaders
|
||||||
|
import io.ktor.http.HttpStatusCode
|
||||||
|
import io.ktor.http.Parameters
|
||||||
|
import io.ktor.http.content.PartData
|
||||||
|
import kotlinx.serialization.DeserializationStrategy
|
||||||
|
import kotlinx.serialization.StringFormat
|
||||||
|
import kotlinx.serialization.encodeToString
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will execute submitting of multipart data request
|
||||||
|
*
|
||||||
|
* @param data [Map] where keys will be used as names for multipart parts and values as values. If you will pass
|
||||||
|
* [dev.inmo.micro_utils.common.MPPFile] (File from JS or JVM platform). Also you may pass [UniUploadFileInfo] as value
|
||||||
|
* in case you wish to pass other source of multipart binary data than regular file
|
||||||
|
*/
|
||||||
|
actual suspend fun <T> HttpClient.uniUpload(
|
||||||
|
url: String,
|
||||||
|
data: Map<String, Any>,
|
||||||
|
resultDeserializer: DeserializationStrategy<T>,
|
||||||
|
headers: Headers,
|
||||||
|
stringFormat: StringFormat,
|
||||||
|
onUpload: OnUploadCallback
|
||||||
|
): T? {
|
||||||
|
val withBinary = data.values.any { it is File || it is UniUploadFileInfo }
|
||||||
|
|
||||||
|
val formData = formData {
|
||||||
|
data.forEach { (k, v) ->
|
||||||
|
when (v) {
|
||||||
|
is File -> append(
|
||||||
|
k,
|
||||||
|
v.inputProviderSync(),
|
||||||
|
Headers.build {
|
||||||
|
append(HttpHeaders.ContentType, v.mimeType)
|
||||||
|
append(HttpHeaders.ContentDisposition, "filename=\"${v.name}\"")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
is UniUploadFileInfo -> append(
|
||||||
|
k,
|
||||||
|
InputProvider(block = v.inputAllocator),
|
||||||
|
Headers.build {
|
||||||
|
append(HttpHeaders.ContentType, v.mimeType)
|
||||||
|
append(HttpHeaders.ContentDisposition, "filename=\"${v.fileName.name}\"")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
else -> append(
|
||||||
|
k,
|
||||||
|
stringFormat.encodeToString(v)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val requestBuilder: HttpRequestBuilder.() -> Unit = {
|
||||||
|
headers {
|
||||||
|
appendAll(headers)
|
||||||
|
}
|
||||||
|
onUpload { bytesSentTotal, contentLength ->
|
||||||
|
onUpload(bytesSentTotal, contentLength)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val response = if (withBinary) {
|
||||||
|
submitFormWithBinaryData(
|
||||||
|
url,
|
||||||
|
formData,
|
||||||
|
block = requestBuilder
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
submitForm(
|
||||||
|
url,
|
||||||
|
Parameters.build {
|
||||||
|
formData.forEach {
|
||||||
|
val formItem = (it as PartData.FormItem)
|
||||||
|
append(it.name!!, it.value)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
block = requestBuilder
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return if (response.status == HttpStatusCode.OK) {
|
||||||
|
stringFormat.decodeFromString(resultDeserializer, response.bodyAsText())
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,5 @@
|
|||||||
|
package dev.inmo.micro_utils.ktor.common
|
||||||
|
|
||||||
|
import io.ktor.utils.io.core.Input
|
||||||
|
|
||||||
|
typealias LambdaInputProvider = () -> Input
|
@@ -0,0 +1,56 @@
|
|||||||
|
package dev.inmo.micro_utils.ktor.server
|
||||||
|
|
||||||
|
import com.benasher44.uuid.uuid4
|
||||||
|
import io.ktor.http.content.PartData
|
||||||
|
import io.ktor.utils.io.copyTo
|
||||||
|
import io.ktor.utils.io.core.copyTo
|
||||||
|
import io.ktor.utils.io.jvm.javaio.copyTo
|
||||||
|
import io.ktor.utils.io.streams.asOutput
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
fun PartData.FileItem.download(target: File) {
|
||||||
|
provider().use { input ->
|
||||||
|
target.outputStream().use {
|
||||||
|
input.copyTo(it.asOutput())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun PartData.FileItem.downloadToTemporalFile(): File {
|
||||||
|
val outputFile = File.createTempFile(uuid4().toString(), ".temp").apply {
|
||||||
|
deleteOnExit()
|
||||||
|
}
|
||||||
|
download(outputFile)
|
||||||
|
return outputFile
|
||||||
|
}
|
||||||
|
|
||||||
|
fun PartData.BinaryItem.download(target: File) {
|
||||||
|
provider().use { input ->
|
||||||
|
target.outputStream().use {
|
||||||
|
input.copyTo(it.asOutput())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun PartData.BinaryItem.downloadToTemporalFile(): File {
|
||||||
|
val outputFile = File.createTempFile(uuid4().toString(), ".temp").apply {
|
||||||
|
deleteOnExit()
|
||||||
|
}
|
||||||
|
download(outputFile)
|
||||||
|
return outputFile
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun PartData.BinaryChannelItem.download(target: File) {
|
||||||
|
val input = provider()
|
||||||
|
target.outputStream().use {
|
||||||
|
input.copyTo(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun PartData.BinaryChannelItem.downloadToTemporalFile(): File {
|
||||||
|
val outputFile = File.createTempFile(uuid4().toString(), ".temp").apply {
|
||||||
|
deleteOnExit()
|
||||||
|
}
|
||||||
|
download(outputFile)
|
||||||
|
return outputFile
|
||||||
|
}
|
@@ -0,0 +1,25 @@
|
|||||||
|
package dev.inmo.micro_utils.ktor.server
|
||||||
|
|
||||||
|
import io.ktor.http.HttpStatusCode
|
||||||
|
import io.ktor.server.application.ApplicationCall
|
||||||
|
import io.ktor.server.response.respond
|
||||||
|
|
||||||
|
suspend fun ApplicationCall.getParameterOrSendError(
|
||||||
|
field: String
|
||||||
|
) = parameters[field].also {
|
||||||
|
if (it == null) {
|
||||||
|
respond(HttpStatusCode.BadRequest, "Request must contains $field")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ApplicationCall.getQueryParameter(
|
||||||
|
field: String
|
||||||
|
) = request.queryParameters[field]
|
||||||
|
|
||||||
|
suspend fun ApplicationCall.getQueryParameterOrSendError(
|
||||||
|
field: String
|
||||||
|
) = getQueryParameter(field).also {
|
||||||
|
if (it == null) {
|
||||||
|
respond(HttpStatusCode.BadRequest, "Request query parameters must contains $field")
|
||||||
|
}
|
||||||
|
}
|
@@ -2,22 +2,34 @@ package dev.inmo.micro_utils.ktor.server
|
|||||||
|
|
||||||
import dev.inmo.micro_utils.common.*
|
import dev.inmo.micro_utils.common.*
|
||||||
import dev.inmo.micro_utils.coroutines.safely
|
import dev.inmo.micro_utils.coroutines.safely
|
||||||
import dev.inmo.micro_utils.ktor.common.*
|
|
||||||
import io.ktor.http.*
|
|
||||||
import io.ktor.http.content.*
|
import io.ktor.http.content.*
|
||||||
import io.ktor.server.application.ApplicationCall
|
import io.ktor.server.application.ApplicationCall
|
||||||
import io.ktor.server.application.call
|
|
||||||
import io.ktor.server.request.receive
|
|
||||||
import io.ktor.server.request.receiveMultipart
|
import io.ktor.server.request.receiveMultipart
|
||||||
import io.ktor.server.response.respond
|
|
||||||
import io.ktor.server.response.respondBytes
|
|
||||||
import io.ktor.server.routing.Route
|
|
||||||
import io.ktor.server.websocket.WebSocketServerSession
|
|
||||||
import io.ktor.util.pipeline.PipelineContext
|
|
||||||
import io.ktor.utils.io.core.*
|
import io.ktor.utils.io.core.*
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.currentCoroutineContext
|
||||||
import kotlinx.serialization.DeserializationStrategy
|
import kotlinx.coroutines.isActive
|
||||||
import kotlinx.serialization.SerializationStrategy
|
|
||||||
|
/**
|
||||||
|
* Server-side part which receives [dev.inmo.micro_utils.ktor.client.uniUpload] request
|
||||||
|
*/
|
||||||
|
suspend inline fun ApplicationCall.handleUniUpload(
|
||||||
|
onFormItem: (PartData.FormItem) -> Unit = {},
|
||||||
|
onBinaryContent: (PartData.BinaryItem) -> Unit = {},
|
||||||
|
onBinaryChannelItem: (PartData.BinaryChannelItem) -> Unit = {},
|
||||||
|
onFileItem: (PartData.FileItem) -> Unit = {}
|
||||||
|
) {
|
||||||
|
val multipartData = receiveMultipart()
|
||||||
|
|
||||||
|
while (currentCoroutineContext().isActive) {
|
||||||
|
val partData = multipartData.readPart() ?: break
|
||||||
|
when (partData) {
|
||||||
|
is PartData.FormItem -> onFormItem(partData)
|
||||||
|
is PartData.FileItem -> onFileItem(partData)
|
||||||
|
is PartData.BinaryItem -> onBinaryContent(partData)
|
||||||
|
is PartData.BinaryChannelItem -> onBinaryChannelItem(partData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
suspend fun ApplicationCall.uniloadMultipart(
|
suspend fun ApplicationCall.uniloadMultipart(
|
||||||
onFormItem: (PartData.FormItem) -> Unit = {},
|
onFormItem: (PartData.FormItem) -> Unit = {},
|
||||||
@@ -25,21 +37,16 @@ suspend fun ApplicationCall.uniloadMultipart(
|
|||||||
onBinaryChannelItem: (PartData.BinaryChannelItem) -> Unit = {},
|
onBinaryChannelItem: (PartData.BinaryChannelItem) -> Unit = {},
|
||||||
onBinaryContent: (PartData.BinaryItem) -> Unit = {}
|
onBinaryContent: (PartData.BinaryItem) -> Unit = {}
|
||||||
) = safely {
|
) = safely {
|
||||||
val multipartData = receiveMultipart()
|
|
||||||
|
|
||||||
var resultInput: Input? = null
|
var resultInput: Input? = null
|
||||||
|
|
||||||
multipartData.forEachPart {
|
handleUniUpload(
|
||||||
when (it) {
|
onFormItem,
|
||||||
is PartData.FormItem -> onFormItem(it)
|
onBinaryContent,
|
||||||
is PartData.FileItem -> {
|
onBinaryChannelItem
|
||||||
when (it.name) {
|
) {
|
||||||
"bytes" -> resultInput = it.provider()
|
when (it.name) {
|
||||||
else -> onCustomFileItem(it)
|
"bytes" -> resultInput = it.provider()
|
||||||
}
|
else -> onCustomFileItem(it)
|
||||||
}
|
|
||||||
is PartData.BinaryItem -> onBinaryContent(it)
|
|
||||||
is PartData.BinaryChannelItem -> onBinaryChannelItem(it)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,23 +96,3 @@ suspend fun ApplicationCall.uniloadMultipartFile(
|
|||||||
|
|
||||||
resultInput ?: error("Bytes has not been received")
|
resultInput ?: error("Bytes has not been received")
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun ApplicationCall.getParameterOrSendError(
|
|
||||||
field: String
|
|
||||||
) = parameters[field].also {
|
|
||||||
if (it == null) {
|
|
||||||
respond(HttpStatusCode.BadRequest, "Request must contains $field")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun ApplicationCall.getQueryParameter(
|
|
||||||
field: String
|
|
||||||
) = request.queryParameters[field]
|
|
||||||
|
|
||||||
suspend fun ApplicationCall.getQueryParameterOrSendError(
|
|
||||||
field: String
|
|
||||||
) = getQueryParameter(field).also {
|
|
||||||
if (it == null) {
|
|
||||||
respond(HttpStatusCode.BadRequest, "Request query parameters must contains $field")
|
|
||||||
}
|
|
||||||
}
|
|
@@ -19,29 +19,29 @@ publishing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
developers {
|
developers {
|
||||||
|
|
||||||
developer {
|
developer {
|
||||||
id = "InsanusMokrassar"
|
id = "InsanusMokrassar"
|
||||||
name = "Aleksei Ovsiannikov"
|
name = "Aleksei Ovsiannikov"
|
||||||
email = "ovsyannikov.alexey95@gmail.com"
|
email = "ovsyannikov.alexey95@gmail.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
developer {
|
developer {
|
||||||
id = "000Sanya"
|
id = "000Sanya"
|
||||||
name = "Syrov Aleksandr"
|
name = "Syrov Aleksandr"
|
||||||
email = "000sanya.000sanya@gmail.com"
|
email = "000sanya.000sanya@gmail.com"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
licenses {
|
licenses {
|
||||||
|
|
||||||
license {
|
license {
|
||||||
name = "Apache Software License 2.0"
|
name = "Apache Software License 2.0"
|
||||||
url = "https://github.com/InsanusMokrassar/MicroUtils/blob/master/LICENSE"
|
url = "https://github.com/InsanusMokrassar/MicroUtils/blob/master/LICENSE"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
repositories {
|
repositories {
|
||||||
@@ -49,35 +49,54 @@ publishing {
|
|||||||
maven {
|
maven {
|
||||||
name = "GithubPackages"
|
name = "GithubPackages"
|
||||||
url = uri("https://maven.pkg.github.com/InsanusMokrassar/MicroUtils")
|
url = uri("https://maven.pkg.github.com/InsanusMokrassar/MicroUtils")
|
||||||
|
|
||||||
credentials {
|
credentials {
|
||||||
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
|
username = project.hasProperty('GITHUBPACKAGES_USER') ? project.property('GITHUBPACKAGES_USER') : System.getenv('GITHUBPACKAGES_USER')
|
||||||
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
|
password = project.hasProperty('GITHUBPACKAGES_PASSWORD') ? project.property('GITHUBPACKAGES_PASSWORD') : System.getenv('GITHUBPACKAGES_PASSWORD')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (project.hasProperty('GITEA_TOKEN') || System.getenv('GITEA_TOKEN') != null) {
|
||||||
|
maven {
|
||||||
|
name = "Gitea"
|
||||||
|
url = uri("https://git.inmo.dev/api/packages/InsanusMokrassar/maven")
|
||||||
|
|
||||||
|
credentials(HttpHeaderCredentials) {
|
||||||
|
name = "Authorization"
|
||||||
|
value = project.hasProperty('GITEA_TOKEN') ? project.property('GITEA_TOKEN') : System.getenv('GITEA_TOKEN')
|
||||||
|
}
|
||||||
|
|
||||||
|
authentication {
|
||||||
|
header(HttpHeaderAuthentication)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
|
if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != null) && (project.hasProperty('SONATYPE_PASSWORD') || System.getenv('SONATYPE_PASSWORD') != null)) {
|
||||||
maven {
|
maven {
|
||||||
name = "sonatype"
|
name = "sonatype"
|
||||||
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
|
url = uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
|
||||||
|
|
||||||
credentials {
|
credentials {
|
||||||
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
|
username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER')
|
||||||
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
|
password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD')
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (project.hasProperty("signing.gnupg.keyName")) {
|
if (project.hasProperty("signing.gnupg.keyName")) {
|
||||||
apply plugin: 'signing'
|
apply plugin: 'signing'
|
||||||
|
|
||||||
signing {
|
signing {
|
||||||
useGpgCmd()
|
useGpgCmd()
|
||||||
|
|
||||||
sign publishing.publications
|
sign publishing.publications
|
||||||
}
|
}
|
||||||
|
|
||||||
task signAll {
|
task signAll {
|
||||||
tasks.withType(Sign).forEach {
|
tasks.withType(Sign).forEach {
|
||||||
dependsOn(it)
|
dependsOn(it)
|
||||||
|
@@ -1 +1 @@
|
|||||||
{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/MicroUtils/blob/master/LICENSE"}],"mavenConfig":{"name":"${project.name}","description":"It is set of projects with micro tools for avoiding of routines coding","url":"https://github.com/InsanusMokrassar/MicroUtils/","vcsUrl":"https://github.com/InsanusMokrassar/MicroUtils.git","developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"},{"id":"000Sanya","name":"Syrov Aleksandr","eMail":"000sanya.000sanya@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/MicroUtils"},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}}
|
{"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://github.com/InsanusMokrassar/MicroUtils/blob/master/LICENSE"}],"mavenConfig":{"name":"${project.name}","description":"It is set of projects with micro tools for avoiding of routines coding","url":"https://github.com/InsanusMokrassar/MicroUtils/","vcsUrl":"https://github.com/InsanusMokrassar/MicroUtils.git","developers":[{"id":"InsanusMokrassar","name":"Aleksei Ovsiannikov","eMail":"ovsyannikov.alexey95@gmail.com"},{"id":"000Sanya","name":"Syrov Aleksandr","eMail":"000sanya.000sanya@gmail.com"}],"repositories":[{"name":"GithubPackages","url":"https://maven.pkg.github.com/InsanusMokrassar/MicroUtils"},{"name":"Gitea","url":"https://git.inmo.dev/api/packages/InsanusMokrassar/maven","credsType":{"type":"dev.inmo.kmppscriptbuilder.core.models.MavenPublishingRepository.CredentialsType.HttpHeaderCredentials","headerName":"Authorization","headerValueProperty":"GITEA_TOKEN"}},{"name":"sonatype","url":"https://oss.sonatype.org/service/local/staging/deploy/maven2/"}],"gpgSigning":{"type":"dev.inmo.kmppscriptbuilder.core.models.GpgSigning.Optional"}}}
|
@@ -28,6 +28,7 @@ kotlin {
|
|||||||
api internalProject("micro_utils.common")
|
api internalProject("micro_utils.common")
|
||||||
api internalProject("micro_utils.coroutines")
|
api internalProject("micro_utils.coroutines")
|
||||||
}
|
}
|
||||||
|
dependsOn jvmMain
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,138 @@
|
|||||||
|
package dev.inmo.micro_utils.repos
|
||||||
|
|
||||||
|
import dev.inmo.micro_utils.pagination.*
|
||||||
|
import dev.inmo.micro_utils.pagination.utils.doAllWithCurrentPaging
|
||||||
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read part of [KeyValueRepo]
|
||||||
|
*
|
||||||
|
* @param Key This type will be used as key in all operations related to searches of data
|
||||||
|
* @param Value This type will be used as returning data in most "get" operations
|
||||||
|
*/
|
||||||
|
interface ReadKeyValueRepo<Key, Value> : Repo {
|
||||||
|
/**
|
||||||
|
* @return Result [Value] in case when it is presented in repo by its [k] or null otherwise
|
||||||
|
*/
|
||||||
|
suspend fun get(k: Key): Value?
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method should use sorted by [Key]s search and take the [PaginationResult]. By default, it should use
|
||||||
|
* ascending sort for [Key]s
|
||||||
|
*/
|
||||||
|
suspend fun values(pagination: Pagination, reversed: Boolean = false): PaginationResult<Value>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method should use sorted by [Key]s search and take the [PaginationResult]. By default, it should use
|
||||||
|
* ascending sort for [Key]s
|
||||||
|
*/
|
||||||
|
suspend fun keys(pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method should use sorted by [Key]s search and take the [PaginationResult]. By default, it should use
|
||||||
|
* ascending sort for [Key]s
|
||||||
|
*
|
||||||
|
* @param v This value should be used to exclude from search the items with different [Value]s
|
||||||
|
*/
|
||||||
|
suspend fun keys(v: Value, pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if [key] is presented in current collection or false otherwise
|
||||||
|
*/
|
||||||
|
suspend fun contains(key: Key): Boolean
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return count of all collection objects
|
||||||
|
*/
|
||||||
|
suspend fun count(): Long
|
||||||
|
}
|
||||||
|
typealias ReadStandardKeyValueRepo<Key,Value> = ReadKeyValueRepo<Key, Value>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write part of [KeyValueRepo]
|
||||||
|
*
|
||||||
|
* @param Key This type will be used as key in all operations related to changes of data
|
||||||
|
* @param Value This type will be used as incoming data in most operations
|
||||||
|
*/
|
||||||
|
interface WriteKeyValueRepo<Key, Value> : Repo {
|
||||||
|
/**
|
||||||
|
* This flow must emit data each time when data by [Key] has been changed with [set] method or in any other way
|
||||||
|
* excluding cases of data removing
|
||||||
|
*
|
||||||
|
* @see onValueRemoved
|
||||||
|
*/
|
||||||
|
val onNewValue: Flow<Pair<Key, Value>>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This flow must emit data each time when data by [Key] has been removed with [unset]/[unsetWithValues] methods or
|
||||||
|
* in any other way
|
||||||
|
*
|
||||||
|
* @see onNewValue
|
||||||
|
*/
|
||||||
|
val onValueRemoved: Flow<Key>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will set as batch [toSet] data in current repo. Must pass the data which were successfully updated in repo to
|
||||||
|
* [onNewValue]
|
||||||
|
*/
|
||||||
|
suspend fun set(toSet: Map<Key, Value>)
|
||||||
|
/**
|
||||||
|
* Will unset as batch data with keys from [toUnset]. Must pass the [Key]s which were successfully removed in repo to
|
||||||
|
* [onValueRemoved]
|
||||||
|
*/
|
||||||
|
suspend fun unset(toUnset: List<Key>)
|
||||||
|
/**
|
||||||
|
* Will unset as batch data with values from [toUnset]. Must pass the [Key]s which were successfully removed in repo
|
||||||
|
* to [onValueRemoved]
|
||||||
|
*/
|
||||||
|
suspend fun unsetWithValues(toUnset: List<Value>)
|
||||||
|
}
|
||||||
|
typealias WriteStandardKeyValueRepo<Key,Value> = WriteKeyValueRepo<Key, Value>
|
||||||
|
|
||||||
|
suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.set(
|
||||||
|
vararg toSet: Pair<Key, Value>
|
||||||
|
) = set(toSet.toMap())
|
||||||
|
|
||||||
|
suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.set(
|
||||||
|
k: Key, v: Value
|
||||||
|
) = set(k to v)
|
||||||
|
|
||||||
|
suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.unset(
|
||||||
|
vararg k: Key
|
||||||
|
) = unset(k.toList())
|
||||||
|
|
||||||
|
suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.unsetWithValues(
|
||||||
|
vararg v: Value
|
||||||
|
) = unsetWithValues(v.toList())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Full version of standard key-value repository with all set/unset/clear/get methods
|
||||||
|
*/
|
||||||
|
interface KeyValueRepo<Key, Value> : ReadKeyValueRepo<Key, Value>, WriteKeyValueRepo<Key, Value> {
|
||||||
|
/**
|
||||||
|
* By default, will walk throw all the [keys] with [Value]s from [toUnset] and run [doAllWithCurrentPaging] with
|
||||||
|
* [unset] of found data [Key]s
|
||||||
|
*/
|
||||||
|
override suspend fun unsetWithValues(toUnset: List<Value>) = toUnset.forEach { v ->
|
||||||
|
doAllWithCurrentPaging {
|
||||||
|
keys(v, it).also {
|
||||||
|
unset(it.results)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* By default, will remove all the data of current repo using [doAllWithCurrentPaging], [keys] and [unset]
|
||||||
|
*/
|
||||||
|
suspend fun clear() {
|
||||||
|
doAllWithCurrentPaging { keys(it).also { unset(it.results) } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
typealias StandardKeyValueRepo<Key,Value> = KeyValueRepo<Key, Value>
|
||||||
|
|
||||||
|
class DelegateBasedKeyValueRepo<Key, Value>(
|
||||||
|
readDelegate: ReadKeyValueRepo<Key, Value>,
|
||||||
|
writeDelegate: WriteKeyValueRepo<Key, Value>
|
||||||
|
) : KeyValueRepo<Key, Value>,
|
||||||
|
ReadKeyValueRepo<Key, Value> by readDelegate,
|
||||||
|
WriteKeyValueRepo<Key, Value> by writeDelegate
|
@@ -1,63 +0,0 @@
|
|||||||
package dev.inmo.micro_utils.repos
|
|
||||||
|
|
||||||
import dev.inmo.micro_utils.pagination.*
|
|
||||||
import dev.inmo.micro_utils.pagination.utils.doAllWithCurrentPaging
|
|
||||||
import kotlinx.coroutines.flow.Flow
|
|
||||||
|
|
||||||
interface ReadKeyValueRepo<Key, Value> : Repo {
|
|
||||||
suspend fun get(k: Key): Value?
|
|
||||||
suspend fun values(pagination: Pagination, reversed: Boolean = false): PaginationResult<Value>
|
|
||||||
suspend fun keys(pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
|
|
||||||
suspend fun keys(v: Value, pagination: Pagination, reversed: Boolean = false): PaginationResult<Key>
|
|
||||||
suspend fun contains(key: Key): Boolean
|
|
||||||
suspend fun count(): Long
|
|
||||||
}
|
|
||||||
typealias ReadStandardKeyValueRepo<Key,Value> = ReadKeyValueRepo<Key, Value>
|
|
||||||
|
|
||||||
interface WriteKeyValueRepo<Key, Value> : Repo {
|
|
||||||
val onNewValue: Flow<Pair<Key, Value>>
|
|
||||||
val onValueRemoved: Flow<Key>
|
|
||||||
|
|
||||||
suspend fun set(toSet: Map<Key, Value>)
|
|
||||||
suspend fun unset(toUnset: List<Key>)
|
|
||||||
suspend fun unsetWithValues(toUnset: List<Value>)
|
|
||||||
}
|
|
||||||
typealias WriteStandardKeyValueRepo<Key,Value> = WriteKeyValueRepo<Key, Value>
|
|
||||||
|
|
||||||
suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.set(
|
|
||||||
vararg toSet: Pair<Key, Value>
|
|
||||||
) = set(toSet.toMap())
|
|
||||||
|
|
||||||
suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.set(
|
|
||||||
k: Key, v: Value
|
|
||||||
) = set(k to v)
|
|
||||||
|
|
||||||
suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.unset(
|
|
||||||
vararg k: Key
|
|
||||||
) = unset(k.toList())
|
|
||||||
|
|
||||||
suspend inline fun <Key, Value> WriteKeyValueRepo<Key, Value>.unsetWithValues(
|
|
||||||
vararg v: Value
|
|
||||||
) = unsetWithValues(v.toList())
|
|
||||||
|
|
||||||
interface KeyValueRepo<Key, Value> : ReadKeyValueRepo<Key, Value>, WriteKeyValueRepo<Key, Value> {
|
|
||||||
override suspend fun unsetWithValues(toUnset: List<Value>) = toUnset.forEach { v ->
|
|
||||||
doAllWithCurrentPaging {
|
|
||||||
keys(v, it).also {
|
|
||||||
unset(it.results)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun clear() {
|
|
||||||
doAllWithCurrentPaging { keys(it).also { unset(it.results) } }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
typealias StandardKeyValueRepo<Key,Value> = KeyValueRepo<Key, Value>
|
|
||||||
|
|
||||||
class DelegateBasedKeyValueRepo<Key, Value>(
|
|
||||||
readDelegate: ReadKeyValueRepo<Key, Value>,
|
|
||||||
writeDelegate: WriteKeyValueRepo<Key, Value>
|
|
||||||
) : KeyValueRepo<Key, Value>,
|
|
||||||
ReadKeyValueRepo<Key, Value> by readDelegate,
|
|
||||||
WriteKeyValueRepo<Key, Value> by writeDelegate
|
|
@@ -50,14 +50,6 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
|
|||||||
val id = createAndInsertId(value, it)
|
val id = createAndInsertId(value, it)
|
||||||
update(id, value, it as UpdateBuilder<Int>)
|
update(id, value, it as UpdateBuilder<Int>)
|
||||||
}
|
}
|
||||||
@Deprecated(
|
|
||||||
"Replace its \"it\" parameter type with \"UpdateBuilder<Int>\" to actualize method signature. Method with current signature will be removed soon and do not recommended to override anymore"
|
|
||||||
)
|
|
||||||
protected open fun update(id: IdType, value: InputValueType, it: UpdateStatement) = update(
|
|
||||||
id,
|
|
||||||
value,
|
|
||||||
it as UpdateBuilder<Int>
|
|
||||||
)
|
|
||||||
|
|
||||||
protected open suspend fun onBeforeCreate(value: List<InputValueType>) {}
|
protected open suspend fun onBeforeCreate(value: List<InputValueType>) {}
|
||||||
|
|
||||||
@@ -137,9 +129,7 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
|
|||||||
override suspend fun deleteById(ids: List<IdType>) {
|
override suspend fun deleteById(ids: List<IdType>) {
|
||||||
onBeforeDelete(ids)
|
onBeforeDelete(ids)
|
||||||
transaction(db = database) {
|
transaction(db = database) {
|
||||||
val deleted = deleteWhere(null, null) {
|
val deleted = deleteWhere(null, null) { selectByIds(it, ids) }
|
||||||
selectByIds(ids)
|
|
||||||
}
|
|
||||||
if (deleted == ids.size) {
|
if (deleted == ids.size) {
|
||||||
ids
|
ids
|
||||||
} else {
|
} else {
|
||||||
|
@@ -4,8 +4,8 @@ import org.jetbrains.exposed.sql.*
|
|||||||
|
|
||||||
interface CommonExposedRepo<IdType, ObjectType> : ExposedRepo {
|
interface CommonExposedRepo<IdType, ObjectType> : ExposedRepo {
|
||||||
val ResultRow.asObject: ObjectType
|
val ResultRow.asObject: ObjectType
|
||||||
val selectById: SqlExpressionBuilder.(IdType) -> Op<Boolean>
|
val selectById: ISqlExpressionBuilder.(IdType) -> Op<Boolean>
|
||||||
val selectByIds: SqlExpressionBuilder.(List<IdType>) -> Op<Boolean>
|
val selectByIds: ISqlExpressionBuilder.(List<IdType>) -> Op<Boolean>
|
||||||
get() = { list ->
|
get() = { list ->
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
Op.FALSE
|
Op.FALSE
|
||||||
|
@@ -27,15 +27,6 @@ abstract class AbstractExposedKeyValueRepo<Key, Value>(
|
|||||||
update(k, v, it as UpdateBuilder<Int>)
|
update(k, v, it as UpdateBuilder<Int>)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated(
|
|
||||||
"Replace its \"it\" parameter type with \"UpdateBuilder<Int>\" to actualize method signature. Method with current signature will be removed soon and do not recommended to override anymore"
|
|
||||||
)
|
|
||||||
protected open fun update(k: Key, v: Value, it: UpdateStatement) = update(
|
|
||||||
k,
|
|
||||||
v,
|
|
||||||
it as UpdateBuilder<Int>
|
|
||||||
)
|
|
||||||
|
|
||||||
override suspend fun set(toSet: Map<Key, Value>) {
|
override suspend fun set(toSet: Map<Key, Value>) {
|
||||||
transaction(database) {
|
transaction(database) {
|
||||||
toSet.mapNotNull { (k, v) ->
|
toSet.mapNotNull { (k, v) ->
|
||||||
@@ -59,9 +50,9 @@ abstract class AbstractExposedKeyValueRepo<Key, Value>(
|
|||||||
|
|
||||||
override suspend fun unset(toUnset: List<Key>) {
|
override suspend fun unset(toUnset: List<Key>) {
|
||||||
transaction(database) {
|
transaction(database) {
|
||||||
toUnset.mapNotNull {
|
toUnset.mapNotNull { item ->
|
||||||
if (deleteWhere { selectById(it) } > 0) {
|
if (deleteWhere { selectById(it, item) } > 0) {
|
||||||
it
|
item
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
@@ -75,7 +66,7 @@ abstract class AbstractExposedKeyValueRepo<Key, Value>(
|
|||||||
transaction(database) {
|
transaction(database) {
|
||||||
toUnset.flatMap {
|
toUnset.flatMap {
|
||||||
val keys = select { selectByValue(it) }.mapNotNull { it.asKey }
|
val keys = select { selectByValue(it) }.mapNotNull { it.asKey }
|
||||||
deleteWhere { selectByIds(keys) }
|
deleteWhere { selectByIds(it, keys) }
|
||||||
keys
|
keys
|
||||||
}
|
}
|
||||||
}.distinct().forEach {
|
}.distinct().forEach {
|
||||||
|
@@ -16,7 +16,7 @@ abstract class AbstractExposedReadKeyValueRepo<Key, Value>(
|
|||||||
Table(tableName ?: "") {
|
Table(tableName ?: "") {
|
||||||
abstract val keyColumn: Column<*>
|
abstract val keyColumn: Column<*>
|
||||||
abstract val ResultRow.asKey: Key
|
abstract val ResultRow.asKey: Key
|
||||||
abstract val selectByValue: SqlExpressionBuilder.(Value) -> Op<Boolean>
|
abstract val selectByValue: ISqlExpressionBuilder.(Value) -> Op<Boolean>
|
||||||
|
|
||||||
override suspend fun get(k: Key): Value? = transaction(database) {
|
override suspend fun get(k: Key): Value? = transaction(database) {
|
||||||
select { selectById(k) }.limit(1).firstOrNull() ?.asObject
|
select { selectById(k) }.limit(1).firstOrNull() ?.asObject
|
||||||
|
@@ -4,6 +4,8 @@ import dev.inmo.micro_utils.repos.KeyValueRepo
|
|||||||
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.inList
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
|
||||||
open class ExposedKeyValueRepo<Key, Value>(
|
open class ExposedKeyValueRepo<Key, Value>(
|
||||||
@@ -47,9 +49,9 @@ open class ExposedKeyValueRepo<Key, Value>(
|
|||||||
|
|
||||||
override suspend fun unset(toUnset: List<Key>) {
|
override suspend fun unset(toUnset: List<Key>) {
|
||||||
transaction(database) {
|
transaction(database) {
|
||||||
toUnset.mapNotNull {
|
toUnset.mapNotNull { item ->
|
||||||
if (deleteWhere { keyColumn.eq(it) } > 0) {
|
if (deleteWhere { keyColumn.eq(item) } > 0) {
|
||||||
it
|
item
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
@@ -20,10 +20,10 @@ open class ExposedReadKeyValueRepo<Key, Value>(
|
|||||||
val valueColumn: Column<Value> = valueColumnAllocator()
|
val valueColumn: Column<Value> = valueColumnAllocator()
|
||||||
override val ResultRow.asKey: Key
|
override val ResultRow.asKey: Key
|
||||||
get() = get(keyColumn)
|
get() = get(keyColumn)
|
||||||
override val selectByValue: SqlExpressionBuilder.(Value) -> Op<Boolean> = { valueColumn.eq(it) }
|
override val selectByValue: ISqlExpressionBuilder.(Value) -> Op<Boolean> = { valueColumn.eq(it) }
|
||||||
override val ResultRow.asObject: Value
|
override val ResultRow.asObject: Value
|
||||||
get() = get(valueColumn)
|
get() = get(valueColumn)
|
||||||
override val selectById: SqlExpressionBuilder.(Key) -> Op<Boolean> = { keyColumn.eq(it) }
|
override val selectById: ISqlExpressionBuilder.(Key) -> Op<Boolean> = { keyColumn.eq(it) }
|
||||||
override val primaryKey: Table.PrimaryKey
|
override val primaryKey: Table.PrimaryKey
|
||||||
get() = PrimaryKey(keyColumn, valueColumn)
|
get() = PrimaryKey(keyColumn, valueColumn)
|
||||||
|
|
||||||
|
@@ -49,7 +49,7 @@ abstract class AbstractExposedKeyValuesRepo<Key, Value>(
|
|||||||
transaction(database) {
|
transaction(database) {
|
||||||
toRemove.keys.flatMap { k ->
|
toRemove.keys.flatMap { k ->
|
||||||
toRemove[k] ?.mapNotNull { v ->
|
toRemove[k] ?.mapNotNull { v ->
|
||||||
if (deleteWhere { selectById(k).and(selectByValue(v)) } > 0 ) {
|
if (deleteWhere { selectById(it, k).and(SqlExpressionBuilder.selectByValue(v)) } > 0 ) {
|
||||||
k to v
|
k to v
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
@@ -63,7 +63,7 @@ abstract class AbstractExposedKeyValuesRepo<Key, Value>(
|
|||||||
|
|
||||||
override suspend fun clear(k: Key) {
|
override suspend fun clear(k: Key) {
|
||||||
transaction(database) {
|
transaction(database) {
|
||||||
deleteWhere { selectById(k) }
|
deleteWhere { selectById(it, k) }
|
||||||
}.also { _onDataCleared.emit(k) }
|
}.also { _onDataCleared.emit(k) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,7 @@ abstract class AbstractExposedReadKeyValuesRepo<Key, Value>(
|
|||||||
Table(tableName ?: "") {
|
Table(tableName ?: "") {
|
||||||
abstract val keyColumn: Column<*>
|
abstract val keyColumn: Column<*>
|
||||||
abstract val ResultRow.asKey: Key
|
abstract val ResultRow.asKey: Key
|
||||||
abstract val selectByValue: SqlExpressionBuilder.(Value) -> Op<Boolean>
|
abstract val selectByValue: ISqlExpressionBuilder.(Value) -> Op<Boolean>
|
||||||
|
|
||||||
override suspend fun count(k: Key): Long = transaction(database) { select { selectById(k) }.count() }
|
override suspend fun count(k: Key): Long = transaction(database) { select { selectById(k) }.count() }
|
||||||
|
|
||||||
|
@@ -4,6 +4,7 @@ import dev.inmo.micro_utils.repos.KeyValuesRepo
|
|||||||
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
import dev.inmo.micro_utils.repos.exposed.ColumnAllocator
|
||||||
import kotlinx.coroutines.flow.*
|
import kotlinx.coroutines.flow.*
|
||||||
import org.jetbrains.exposed.sql.*
|
import org.jetbrains.exposed.sql.*
|
||||||
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
|
||||||
typealias ExposedOneToManyKeyValueRepo1<Key, Value> = ExposedKeyValuesRepo<Key, Value>
|
typealias ExposedOneToManyKeyValueRepo1<Key, Value> = ExposedKeyValuesRepo<Key, Value>
|
||||||
|
@@ -15,10 +15,10 @@ open class ExposedReadKeyValuesRepo<Key, Value>(
|
|||||||
override val keyColumn: Column<Key> = keyColumnAllocator()
|
override val keyColumn: Column<Key> = keyColumnAllocator()
|
||||||
override val ResultRow.asKey: Key
|
override val ResultRow.asKey: Key
|
||||||
get() = get(keyColumn)
|
get() = get(keyColumn)
|
||||||
override val selectByValue: SqlExpressionBuilder.(Value) -> Op<Boolean> = { valueColumn.eq(it) }
|
override val selectByValue: ISqlExpressionBuilder.(Value) -> Op<Boolean> = { valueColumn.eq(it) }
|
||||||
override val ResultRow.asObject: Value
|
override val ResultRow.asObject: Value
|
||||||
get() = get(valueColumn)
|
get() = get(valueColumn)
|
||||||
override val selectById: SqlExpressionBuilder.(Key) -> Op<Boolean> = { keyColumn.eq(it) }
|
override val selectById: ISqlExpressionBuilder.(Key) -> Op<Boolean> = { keyColumn.eq(it) }
|
||||||
val valueColumn: Column<Value> = valueColumnAllocator()
|
val valueColumn: Column<Value> = valueColumnAllocator()
|
||||||
|
|
||||||
init { initTable() }
|
init { initTable() }
|
||||||
|
Reference in New Issue
Block a user