mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-29 13:38:45 +00:00
fix table name parameter in keyvalue and onetomany repos
This commit is contained in:
parent
c5a32e2b1b
commit
02ad1a748e
@ -12,11 +12,13 @@ import org.jetbrains.exposed.sql.transactions.transaction
|
|||||||
open class ExposedKeyValueRepo<Key, Value>(
|
open class ExposedKeyValueRepo<Key, Value>(
|
||||||
database: Database,
|
database: Database,
|
||||||
keyColumnAllocator: ColumnAllocator<Key>,
|
keyColumnAllocator: ColumnAllocator<Key>,
|
||||||
valueColumnAllocator: ColumnAllocator<Value>
|
valueColumnAllocator: ColumnAllocator<Value>,
|
||||||
|
tableName: String? = null
|
||||||
) : StandardKeyValueRepo<Key, Value>, ExposedReadKeyValueRepo<Key, Value>(
|
) : StandardKeyValueRepo<Key, Value>, ExposedReadKeyValueRepo<Key, Value>(
|
||||||
database,
|
database,
|
||||||
keyColumnAllocator,
|
keyColumnAllocator,
|
||||||
valueColumnAllocator
|
valueColumnAllocator,
|
||||||
|
tableName
|
||||||
) {
|
) {
|
||||||
private val onNewValueChannel = BroadcastChannel<Pair<Key, Value>>(Channel.BUFFERED)
|
private val onNewValueChannel = BroadcastChannel<Pair<Key, Value>>(Channel.BUFFERED)
|
||||||
private val onValueRemovedChannel = BroadcastChannel<Key>(Channel.BUFFERED)
|
private val onValueRemovedChannel = BroadcastChannel<Key>(Channel.BUFFERED)
|
||||||
@ -24,8 +26,6 @@ open class ExposedKeyValueRepo<Key, Value>(
|
|||||||
override val onNewValue: Flow<Pair<Key, Value>> = onNewValueChannel.asFlow()
|
override val onNewValue: Flow<Pair<Key, Value>> = onNewValueChannel.asFlow()
|
||||||
override val onValueRemoved: Flow<Key> = onValueRemovedChannel.asFlow()
|
override val onValueRemoved: Flow<Key> = onValueRemovedChannel.asFlow()
|
||||||
|
|
||||||
init { initTable() }
|
|
||||||
|
|
||||||
override suspend fun set(k: Key, v: Value) {
|
override suspend fun set(k: Key, v: Value) {
|
||||||
transaction(database) {
|
transaction(database) {
|
||||||
if (select { keyColumn.eq(k) }.limit(1).any()) {
|
if (select { keyColumn.eq(k) }.limit(1).any()) {
|
||||||
|
@ -10,13 +10,12 @@ open class ExposedReadKeyValueRepo<Key, Value>(
|
|||||||
override val database: Database,
|
override val database: Database,
|
||||||
keyColumnAllocator: ColumnAllocator<Key>,
|
keyColumnAllocator: ColumnAllocator<Key>,
|
||||||
valueColumnAllocator: ColumnAllocator<Value>,
|
valueColumnAllocator: ColumnAllocator<Value>,
|
||||||
) : ReadStandardKeyValueRepo<Key, Value>, ExposedRepo, Table() {
|
tableName: String? = null
|
||||||
|
) : ReadStandardKeyValueRepo<Key, Value>, ExposedRepo, Table(tableName ?: "") {
|
||||||
protected val keyColumn: Column<Key> = keyColumnAllocator()
|
protected val keyColumn: Column<Key> = keyColumnAllocator()
|
||||||
protected val valueColumn: Column<Value> = valueColumnAllocator()
|
protected val valueColumn: Column<Value> = valueColumnAllocator()
|
||||||
override val primaryKey: PrimaryKey = PrimaryKey(keyColumn, valueColumn)
|
override val primaryKey: PrimaryKey = PrimaryKey(keyColumn, valueColumn)
|
||||||
|
|
||||||
init { initTable() }
|
|
||||||
|
|
||||||
override suspend fun get(k: Key): Value? = transaction(database) {
|
override suspend fun get(k: Key): Value? = transaction(database) {
|
||||||
select { keyColumn.eq(k) }.limit(1).firstOrNull() ?.getOrNull(valueColumn)
|
select { keyColumn.eq(k) }.limit(1).firstOrNull() ?.getOrNull(valueColumn)
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,13 @@ import org.jetbrains.exposed.sql.transactions.transaction
|
|||||||
open class ExposedOneToManyKeyValueRepo<Key, Value>(
|
open class ExposedOneToManyKeyValueRepo<Key, Value>(
|
||||||
database: Database,
|
database: Database,
|
||||||
keyColumnAllocator: ColumnAllocator<Key>,
|
keyColumnAllocator: ColumnAllocator<Key>,
|
||||||
valueColumnAllocator: ColumnAllocator<Value>
|
valueColumnAllocator: ColumnAllocator<Value>,
|
||||||
|
tableName: String? = null
|
||||||
) : OneToManyKeyValueRepo<Key, Value>, ExposedReadOneToManyKeyValueRepo<Key, Value>(
|
) : OneToManyKeyValueRepo<Key, Value>, ExposedReadOneToManyKeyValueRepo<Key, Value>(
|
||||||
database,
|
database,
|
||||||
keyColumnAllocator,
|
keyColumnAllocator,
|
||||||
valueColumnAllocator
|
valueColumnAllocator,
|
||||||
|
tableName
|
||||||
) {
|
) {
|
||||||
protected val _onNewValue: BroadcastFlow<Pair<Key, Value>> = BroadcastFlow()
|
protected val _onNewValue: BroadcastFlow<Pair<Key, Value>> = BroadcastFlow()
|
||||||
override val onNewValue: Flow<Pair<Key, Value>>
|
override val onNewValue: Flow<Pair<Key, Value>>
|
||||||
@ -27,8 +29,6 @@ open class ExposedOneToManyKeyValueRepo<Key, Value>(
|
|||||||
override val onDataCleared: Flow<Key>
|
override val onDataCleared: Flow<Key>
|
||||||
get() = _onDataCleared
|
get() = _onDataCleared
|
||||||
|
|
||||||
init { initTable() }
|
|
||||||
|
|
||||||
override suspend fun add(k: Key, v: Value) {
|
override suspend fun add(k: Key, v: Value) {
|
||||||
transaction(database) {
|
transaction(database) {
|
||||||
insert {
|
insert {
|
||||||
|
@ -9,8 +9,9 @@ import org.jetbrains.exposed.sql.transactions.transaction
|
|||||||
open class ExposedReadOneToManyKeyValueRepo<Key, Value>(
|
open class ExposedReadOneToManyKeyValueRepo<Key, Value>(
|
||||||
override val database: Database,
|
override val database: Database,
|
||||||
keyColumnAllocator: ColumnAllocator<Key>,
|
keyColumnAllocator: ColumnAllocator<Key>,
|
||||||
valueColumnAllocator: ColumnAllocator<Value>
|
valueColumnAllocator: ColumnAllocator<Value>,
|
||||||
) : ReadOneToManyKeyValueRepo<Key, Value>, ExposedRepo, Table() {
|
tableName: String? = null
|
||||||
|
) : ReadOneToManyKeyValueRepo<Key, Value>, ExposedRepo, Table(tableName ?: "") {
|
||||||
protected val keyColumn: Column<Key> = keyColumnAllocator()
|
protected val keyColumn: Column<Key> = keyColumnAllocator()
|
||||||
protected val valueColumn: Column<Value> = valueColumnAllocator()
|
protected val valueColumn: Column<Value> = valueColumnAllocator()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user