mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-26 03:58:45 +00:00
update: Replace channels by sharedflows in exposed CRUD realization
This commit is contained in:
parent
7b4c9d59b0
commit
0fdb072385
@ -2,6 +2,10 @@
|
||||
|
||||
## 0.2.8
|
||||
|
||||
* `Repos`:
|
||||
* `Exposed`:
|
||||
* CRUD realizations replaced their channels to shared flows
|
||||
|
||||
## 0.2.7
|
||||
|
||||
* `Versions`:
|
||||
|
@ -1,9 +1,7 @@
|
||||
package dev.inmo.micro_utils.repos.exposed
|
||||
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
|
||||
abstract class AbstractExposedCRUDRepo<ObjectType, IdType, InputValueType>(
|
||||
flowsChannelsSize: Int = Channel.BUFFERED,
|
||||
flowsChannelsSize: Int = 0,
|
||||
tableName: String = ""
|
||||
) :
|
||||
AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
|
||||
|
@ -3,28 +3,27 @@ package dev.inmo.micro_utils.repos.exposed
|
||||
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
|
||||
import kotlinx.coroutines.flow.*
|
||||
import org.jetbrains.exposed.sql.*
|
||||
import org.jetbrains.exposed.sql.statements.InsertStatement
|
||||
import org.jetbrains.exposed.sql.statements.UpdateStatement
|
||||
import org.jetbrains.exposed.sql.transactions.transaction
|
||||
|
||||
abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
|
||||
flowsChannelsSize: Int = 64,
|
||||
flowsChannelsSize: Int = 0,
|
||||
tableName: String = ""
|
||||
) :
|
||||
AbstractExposedReadCRUDRepo<ObjectType, IdType>(tableName),
|
||||
ExposedCRUDRepo<ObjectType, IdType>,
|
||||
WriteStandardCRUDRepo<ObjectType, IdType, InputValueType>
|
||||
{
|
||||
protected val newObjectsChannel = BroadcastChannel<ObjectType>(flowsChannelsSize)
|
||||
protected val updateObjectsChannel = BroadcastChannel<ObjectType>(flowsChannelsSize)
|
||||
protected val deleteObjectsIdsChannel = BroadcastChannel<IdType>(flowsChannelsSize)
|
||||
protected val newObjectsChannel = MutableSharedFlow<ObjectType>(flowsChannelsSize)
|
||||
protected val updateObjectsChannel = MutableSharedFlow<ObjectType>(flowsChannelsSize)
|
||||
protected val deleteObjectsIdsChannel = MutableSharedFlow<IdType>(flowsChannelsSize)
|
||||
|
||||
override val newObjectsFlow: Flow<ObjectType> = newObjectsChannel.asFlow()
|
||||
override val updatedObjectsFlow: Flow<ObjectType> = updateObjectsChannel.asFlow()
|
||||
override val deletedObjectsIdsFlow: Flow<IdType> = deleteObjectsIdsChannel.asFlow()
|
||||
override val newObjectsFlow: Flow<ObjectType> = newObjectsChannel.asSharedFlow()
|
||||
override val updatedObjectsFlow: Flow<ObjectType> = updateObjectsChannel.asSharedFlow()
|
||||
override val deletedObjectsIdsFlow: Flow<IdType> = deleteObjectsIdsChannel.asSharedFlow()
|
||||
|
||||
abstract val InsertStatement<Number>.asObject: ObjectType
|
||||
abstract val selectByIds: SqlExpressionBuilder.(List<out IdType>) -> Op<Boolean>
|
||||
@ -45,7 +44,7 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
|
||||
values.map { value -> createWithoutNotification(value) }
|
||||
}.also {
|
||||
it.forEach {
|
||||
newObjectsChannel.send(it)
|
||||
newObjectsChannel.emit(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -75,7 +74,7 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
|
||||
onBeforeUpdate(listOf(id to value))
|
||||
return updateWithoutNotification(id, value).also {
|
||||
if (it != null) {
|
||||
updateObjectsChannel.send(it)
|
||||
updateObjectsChannel.emit(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -89,7 +88,7 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
|
||||
} as List<ObjectType>
|
||||
).also {
|
||||
it.forEach {
|
||||
updateObjectsChannel.send(it)
|
||||
updateObjectsChannel.emit(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user