diff --git a/CHANGELOG.md b/CHANGELOG.md index b8ddee40a15..47f358bfd57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 0.9.21 + +* `Repos`: + * `Exposed`: + * fixes in `AbstractExposedWriteCRUDRepo` + ## 0.9.20 * `Repos`: diff --git a/gradle.properties b/gradle.properties index fc33e33ef90..0bd6476919b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,5 +14,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.9.20 -android_code_version=110 +version=0.9.21 +android_code_version=111 diff --git a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt index 81de84d04b6..c64d9c47f91 100644 --- a/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt +++ b/repos/exposed/src/jvmMain/kotlin/dev/inmo/micro_utils/repos/exposed/AbstractExposedWriteCRUDRepo.kt @@ -17,13 +17,19 @@ abstract class AbstractExposedWriteCRUDRepo( ExposedCRUDRepo, WriteStandardCRUDRepo { - protected val newObjectsChannel = MutableSharedFlow(replyCacheInFlows, flowsChannelsSize) - protected val updateObjectsChannel = MutableSharedFlow(replyCacheInFlows, flowsChannelsSize) - protected val deleteObjectsIdsChannel = MutableSharedFlow(replyCacheInFlows, flowsChannelsSize) + protected val _newObjectsFlow = MutableSharedFlow(replyCacheInFlows, flowsChannelsSize) + protected val _updatedObjectsFlow = MutableSharedFlow(replyCacheInFlows, flowsChannelsSize) + protected val _deletedObjectsIdsFlow = MutableSharedFlow(replyCacheInFlows, flowsChannelsSize) + @Deprecated("Renamed", ReplaceWith("_newObjectsFlow")) + protected val newObjectsChannel = _newObjectsFlow + @Deprecated("Renamed", ReplaceWith("_updatedObjectsFlow")) + protected val updateObjectsChannel = _updatedObjectsFlow + @Deprecated("Renamed", ReplaceWith("_deletedObjectsIdsFlow")) + protected val deleteObjectsIdsChannel = _deletedObjectsIdsFlow - override val newObjectsFlow: Flow = newObjectsChannel.asSharedFlow() - override val updatedObjectsFlow: Flow = updateObjectsChannel.asSharedFlow() - override val deletedObjectsIdsFlow: Flow = deleteObjectsIdsChannel.asSharedFlow() + override val newObjectsFlow: Flow = _newObjectsFlow.asSharedFlow() + override val updatedObjectsFlow: Flow = _updatedObjectsFlow.asSharedFlow() + override val deletedObjectsIdsFlow: Flow = _deletedObjectsIdsFlow.asSharedFlow() protected abstract fun InsertStatement.asObject(value: InputValueType): ObjectType abstract val selectByIds: SqlExpressionBuilder.(List) -> Op @@ -43,7 +49,7 @@ abstract class AbstractExposedWriteCRUDRepo( return transaction(db = database) { values.map { value -> createWithoutNotification(value) } }.onEach { - newObjectsChannel.emit(it) + _newObjectsFlow.emit(it) } } @@ -74,7 +80,7 @@ abstract class AbstractExposedWriteCRUDRepo( onBeforeUpdate(listOf(id to value)) return updateWithoutNotification(id, value).also { if (it != null) { - updateObjectsChannel.emit(it) + _updatedObjectsFlow.emit(it) } } } @@ -85,16 +91,25 @@ abstract class AbstractExposedWriteCRUDRepo( values.map { (id, value) -> updateWithoutNotification(id, value) } }.filterNotNull() ).onEach { - updateObjectsChannel.emit(it) + _updatedObjectsFlow.emit(it) } } protected open suspend fun onBeforeDelete(ids: List) {} override suspend fun deleteById(ids: List) { onBeforeDelete(ids) transaction(db = database) { - deleteWhere(null, null) { + val deleted = deleteWhere(null, null) { selectByIds(ids) } + if (deleted == ids.size) { + ids + } else { + ids.filter { + select { selectById(it) }.limit(1).none() + } + } + }.forEach { + _deletedObjectsIdsFlow.emit(it) } } }