mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-12-21 08:07:16 +00:00
implemented coroutines and exposed utils
This commit is contained in:
parent
1dcf17a35d
commit
5a5519c7cb
16
coroutines/build.gradle
Normal file
16
coroutines/build.gradle
Normal file
@ -0,0 +1,16 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package dev.inmo.micro_utils.coroutines
|
||||
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.supervisorScope
|
||||
|
||||
|
||||
typealias ExceptionHandler<T> = suspend (Throwable) -> T
|
||||
/**
|
||||
* It will run [block] inside of [supervisorScope] to avoid problems with catching of exceptions
|
||||
*
|
||||
* @param [onException] Will be called when happen exception inside of [block]. By default will throw exception - this
|
||||
* exception will be available for catching
|
||||
*/
|
||||
suspend inline fun <T> safely(
|
||||
noinline onException: ExceptionHandler<T> = { throw it },
|
||||
noinline block: suspend CoroutineScope.() -> T
|
||||
): T {
|
||||
return try {
|
||||
supervisorScope(block)
|
||||
} catch (e: Throwable) {
|
||||
onException(e)
|
||||
}
|
||||
}
|
16
exposed/build.gradle
Normal file
16
exposed/build.gradle
Normal file
@ -0,0 +1,16 @@
|
||||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
}
|
||||
|
||||
apply from: "$mppJavaProjectPresetPath"
|
||||
|
||||
kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package dev.inmo.micro_utils.exposed
|
||||
|
||||
import dev.inmo.micro_utils.pagination.*
|
||||
import org.jetbrains.exposed.sql.*
|
||||
|
||||
fun Query.paginate(with: Pagination, orderBy: Pair<Expression<*>, SortOrder>? = null) = limit(
|
||||
with.size,
|
||||
(if (orderBy ?.second == SortOrder.DESC) {
|
||||
with.lastIndex
|
||||
} else {
|
||||
with.firstIndex
|
||||
}).toLong()
|
||||
).let {
|
||||
if (orderBy != null) {
|
||||
it.orderBy(
|
||||
orderBy.first,
|
||||
orderBy.second
|
||||
)
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
|
||||
fun Query.paginate(with: Pagination, orderBy: Expression<*>?, reversed: Boolean = false) = paginate(
|
||||
with,
|
||||
orderBy ?.let { it to if (reversed) SortOrder.DESC else SortOrder.ASC }
|
||||
)
|
@ -10,6 +10,7 @@ kotlin {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api internalProject("micro_utils.ktor.common")
|
||||
api internalProject("micro_utils.coroutines")
|
||||
api "io.ktor:ktor-client:$ktor_version"
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.inmo.micro_utils.ktor.client
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.safely
|
||||
import dev.inmo.micro_utils.ktor.common.asCorrectWebSocketUrl
|
||||
import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat
|
||||
import io.ktor.client.HttpClient
|
||||
|
@ -9,6 +9,7 @@ kotlin {
|
||||
sourceSets {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api "org.jetbrains.kotlinx:kotlinx-serialization-cbor:$kotlin_serialisation_core_version"
|
||||
api "com.soywiz.korlibs.klock:klock:$klockVersion"
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ kotlin {
|
||||
commonMain {
|
||||
dependencies {
|
||||
api internalProject("micro_utils.ktor.common")
|
||||
api internalProject("micro_utils.coroutines")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package dev.inmo.micro_utils.ktor.server
|
||||
|
||||
import dev.inmo.micro_utils.coroutines.safely
|
||||
import dev.inmo.micro_utils.ktor.common.CorrectCloseException
|
||||
import dev.inmo.micro_utils.ktor.common.standardKtorSerialFormat
|
||||
import io.ktor.http.cio.websocket.*
|
||||
|
@ -12,5 +12,10 @@ kotlin {
|
||||
api internalProject("micro_utils.repos.common")
|
||||
}
|
||||
}
|
||||
jvmMain {
|
||||
dependencies {
|
||||
api internalProject("micro_utils.exposed")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
package dev.inmo.micro_utils.repos.exposed
|
||||
|
||||
import com.insanusmokrassar.postssystem.exposed.commons.paginate
|
||||
import com.insanusmokrassar.postssystem.utils.common.pagination.*
|
||||
import com.insanusmokrassar.postssystem.utils.repos.ReadStandardCRUDRepo
|
||||
import dev.inmo.micro_utils.exposed.paginate
|
||||
import dev.inmo.micro_utils.pagination.Pagination
|
||||
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||
import dev.inmo.micro_utils.pagination.createPaginationResult
|
||||
import dev.inmo.micro_utils.repos.ReadStandardCRUDRepo
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package dev.inmo.micro_utils.repos.exposed
|
||||
|
||||
import com.insanusmokrassar.postssystem.utils.repos.UpdatedValuePair
|
||||
import com.insanusmokrassar.postssystem.utils.repos.WriteStandardCRUDRepo
|
||||
import dev.inmo.micro_utils.repos.UpdatedValuePair
|
||||
import dev.inmo.micro_utils.repos.WriteStandardCRUDRepo
|
||||
import kotlinx.coroutines.channels.BroadcastChannel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.inmo.micro_utils.repos.exposed.keyvalue
|
||||
|
||||
import com.insanusmokrassar.postssystem.utils.repos.StandardKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.StandardKeyValueRepo
|
||||
import kotlinx.coroutines.channels.BroadcastChannel
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
@ -1,8 +1,10 @@
|
||||
package dev.inmo.micro_utils.repos.exposed.keyvalue
|
||||
|
||||
import com.insanusmokrassar.postssystem.exposed.commons.paginate
|
||||
import com.insanusmokrassar.postssystem.utils.common.pagination.*
|
||||
import com.insanusmokrassar.postssystem.utils.repos.StandardReadKeyValueRepo
|
||||
import dev.inmo.micro_utils.exposed.paginate
|
||||
import dev.inmo.micro_utils.pagination.Pagination
|
||||
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||
import dev.inmo.micro_utils.pagination.createPaginationResult
|
||||
import dev.inmo.micro_utils.repos.StandardReadKeyValueRepo
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
|
@ -1,8 +1,6 @@
|
||||
package dev.inmo.micro_utils.repos.exposed.onetomany
|
||||
|
||||
import com.insanusmokrassar.budgetmanager.core.utils.repo.onetomany.AbstractOneToManyExposedReadKeyValueRepo
|
||||
import com.insanusmokrassar.budgetmanager.core.utils.repo.onetomany.ColumnAllocator
|
||||
import com.insanusmokrassar.postssystem.utils.repos.OneToManyKeyValueRepo
|
||||
import dev.inmo.micro_utils.repos.OneToManyKeyValueRepo
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
package dev.inmo.micro_utils.repos.exposed.onetomany
|
||||
|
||||
import com.insanusmokrassar.postssystem.exposed.commons.paginate
|
||||
import com.insanusmokrassar.postssystem.utils.common.pagination.*
|
||||
import com.insanusmokrassar.postssystem.utils.repos.OneToManyReadKeyValueRepo
|
||||
import dev.inmo.micro_utils.exposed.paginate
|
||||
import dev.inmo.micro_utils.pagination.Pagination
|
||||
import dev.inmo.micro_utils.pagination.PaginationResult
|
||||
import dev.inmo.micro_utils.pagination.createPaginationResult
|
||||
import dev.inmo.micro_utils.repos.OneToManyReadKeyValueRepo
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
|
@ -13,6 +13,8 @@ String[] includes = [
|
||||
":ktor:server",
|
||||
":ktor:common",
|
||||
":ktor:client",
|
||||
":coroutines",
|
||||
":exposed"
|
||||
]
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user