improve exposed repos

This commit is contained in:
InsanusMokrassar 2024-04-01 18:20:05 +06:00
parent 6370562dbc
commit 4f7f8abec4
5 changed files with 30 additions and 14 deletions

View File

@ -2,6 +2,10 @@
## 0.20.41 ## 0.20.41
* `Repos`:
* `Exposed`:
* `AbstractExposedKeyValueRepo`, `ExposedKeyValueRepo`, `AbstractExposedKeyValuesRepo`, `ExposedKeyValuesRepo` got opportunity to setup some part of their flows
## 0.20.40 ## 0.20.40
* `Versions`: * `Versions`:

View File

@ -1,6 +1,7 @@
package dev.inmo.micro_utils.repos.exposed.keyvalue package dev.inmo.micro_utils.repos.exposed.keyvalue
import dev.inmo.micro_utils.repos.KeyValueRepo import dev.inmo.micro_utils.repos.KeyValueRepo
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.*
import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.statements.* import org.jetbrains.exposed.sql.statements.*
@ -8,13 +9,15 @@ import org.jetbrains.exposed.sql.transactions.transaction
abstract class AbstractExposedKeyValueRepo<Key, Value>( abstract class AbstractExposedKeyValueRepo<Key, Value>(
override val database: Database, override val database: Database,
tableName: String? = null tableName: String? = null,
flowsExtraBufferCapacity: Int = Int.MAX_VALUE,
flowsBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND
) : KeyValueRepo<Key, Value>, AbstractExposedReadKeyValueRepo<Key, Value>( ) : KeyValueRepo<Key, Value>, AbstractExposedReadKeyValueRepo<Key, Value>(
database, database,
tableName tableName
) { ) {
protected val _onNewValue = MutableSharedFlow<Pair<Key, Value>>() protected val _onNewValue = MutableSharedFlow<Pair<Key, Value>>(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
protected val _onValueRemoved = MutableSharedFlow<Key>() protected val _onValueRemoved = MutableSharedFlow<Key>(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
override val onNewValue: Flow<Pair<Key, Value>> = _onNewValue.asSharedFlow() override val onNewValue: Flow<Pair<Key, Value>> = _onNewValue.asSharedFlow()
override val onValueRemoved: Flow<Key> = _onValueRemoved.asSharedFlow() override val onValueRemoved: Flow<Key> = _onValueRemoved.asSharedFlow()

View File

@ -2,6 +2,7 @@ package dev.inmo.micro_utils.repos.exposed.keyvalue
import dev.inmo.micro_utils.repos.KeyValueRepo 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.channels.BufferOverflow
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.eq
@ -13,15 +14,17 @@ open class ExposedKeyValueRepo<Key, Value>(
database: Database, database: Database,
keyColumnAllocator: ColumnAllocator<Key>, keyColumnAllocator: ColumnAllocator<Key>,
valueColumnAllocator: ColumnAllocator<Value>, valueColumnAllocator: ColumnAllocator<Value>,
tableName: String? = null tableName: String? = null,
flowsExtraBufferCapacity: Int = Int.MAX_VALUE,
flowsBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND
) : KeyValueRepo<Key, Value>, ExposedReadKeyValueRepo<Key, Value>( ) : KeyValueRepo<Key, Value>, ExposedReadKeyValueRepo<Key, Value>(
database, database,
keyColumnAllocator, keyColumnAllocator,
valueColumnAllocator, valueColumnAllocator,
tableName tableName
) { ) {
protected val _onNewValue = MutableSharedFlow<Pair<Key, Value>>() protected val _onNewValue = MutableSharedFlow<Pair<Key, Value>>(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
protected val _onValueRemoved = MutableSharedFlow<Key>() protected val _onValueRemoved = MutableSharedFlow<Key>(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
override val onNewValue: Flow<Pair<Key, Value>> = _onNewValue.asSharedFlow() override val onNewValue: Flow<Pair<Key, Value>> = _onNewValue.asSharedFlow()
override val onValueRemoved: Flow<Key> = _onValueRemoved.asSharedFlow() override val onValueRemoved: Flow<Key> = _onValueRemoved.asSharedFlow()

View File

@ -1,6 +1,7 @@
package dev.inmo.micro_utils.repos.exposed.onetomany package dev.inmo.micro_utils.repos.exposed.onetomany
import dev.inmo.micro_utils.repos.KeyValuesRepo import dev.inmo.micro_utils.repos.KeyValuesRepo
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.* import kotlinx.coroutines.flow.*
import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.*
import org.jetbrains.exposed.sql.statements.InsertStatement import org.jetbrains.exposed.sql.statements.InsertStatement
@ -8,18 +9,20 @@ import org.jetbrains.exposed.sql.transactions.transaction
abstract class AbstractExposedKeyValuesRepo<Key, Value>( abstract class AbstractExposedKeyValuesRepo<Key, Value>(
override val database: Database, override val database: Database,
tableName: String? = null tableName: String? = null,
flowsExtraBufferCapacity: Int = Int.MAX_VALUE,
flowsBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND
) : KeyValuesRepo<Key, Value>, AbstractExposedReadKeyValuesRepo<Key, Value>( ) : KeyValuesRepo<Key, Value>, AbstractExposedReadKeyValuesRepo<Key, Value>(
database, database,
tableName tableName
) { ) {
protected val _onNewValue: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow() protected val _onNewValue: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
override val onNewValue: Flow<Pair<Key, Value>> override val onNewValue: Flow<Pair<Key, Value>>
get() = _onNewValue.asSharedFlow() get() = _onNewValue.asSharedFlow()
protected val _onValueRemoved: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow() protected val _onValueRemoved: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
override val onValueRemoved: Flow<Pair<Key, Value>> override val onValueRemoved: Flow<Pair<Key, Value>>
get() = _onValueRemoved.asSharedFlow() get() = _onValueRemoved.asSharedFlow()
protected val _onDataCleared: MutableSharedFlow<Key> = MutableSharedFlow() protected val _onDataCleared: MutableSharedFlow<Key> = MutableSharedFlow(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
override val onDataCleared: Flow<Key> override val onDataCleared: Flow<Key>
get() = _onDataCleared.asSharedFlow() get() = _onDataCleared.asSharedFlow()

View File

@ -2,6 +2,7 @@ package dev.inmo.micro_utils.repos.exposed.onetomany
import dev.inmo.micro_utils.repos.KeyValuesRepo 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.channels.BufferOverflow
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.eq
@ -13,20 +14,22 @@ open class ExposedKeyValuesRepo<Key, Value>(
database: Database, database: Database,
keyColumnAllocator: ColumnAllocator<Key>, keyColumnAllocator: ColumnAllocator<Key>,
valueColumnAllocator: ColumnAllocator<Value>, valueColumnAllocator: ColumnAllocator<Value>,
tableName: String? = null tableName: String? = null,
flowsExtraBufferCapacity: Int = Int.MAX_VALUE,
flowsBufferOverflow: BufferOverflow = BufferOverflow.SUSPEND
) : KeyValuesRepo<Key, Value>, ExposedReadKeyValuesRepo<Key, Value>( ) : KeyValuesRepo<Key, Value>, ExposedReadKeyValuesRepo<Key, Value>(
database, database,
keyColumnAllocator, keyColumnAllocator,
valueColumnAllocator, valueColumnAllocator,
tableName tableName
) { ) {
protected val _onNewValue: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow() protected val _onNewValue: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
override val onNewValue: Flow<Pair<Key, Value>> override val onNewValue: Flow<Pair<Key, Value>>
get() = _onNewValue get() = _onNewValue
protected val _onValueRemoved: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow() protected val _onValueRemoved: MutableSharedFlow<Pair<Key, Value>> = MutableSharedFlow(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
override val onValueRemoved: Flow<Pair<Key, Value>> override val onValueRemoved: Flow<Pair<Key, Value>>
get() = _onValueRemoved get() = _onValueRemoved
protected val _onDataCleared: MutableSharedFlow<Key> = MutableSharedFlow() protected val _onDataCleared: MutableSharedFlow<Key> = MutableSharedFlow(extraBufferCapacity = flowsExtraBufferCapacity, onBufferOverflow = flowsBufferOverflow)
override val onDataCleared: Flow<Key> override val onDataCleared: Flow<Key>
get() = _onDataCleared get() = _onDataCleared