diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a5a73e9baf..9628f3c83a2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ * `Versions`: * `Ktor`: `1.4.2` -> `1.4.3` +* `Repo` + * `Exposed` + * `asObject` open fun has been added in CRUD realization ## 0.4.8 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 869a8a2c50c..bd4c1265c1e 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 @@ -25,8 +25,10 @@ abstract class AbstractExposedWriteCRUDRepo( override val updatedObjectsFlow: Flow = updateObjectsChannel.asSharedFlow() override val deletedObjectsIdsFlow: Flow = deleteObjectsIdsChannel.asSharedFlow() + @Deprecated("Will be removed in near major update. Override open fun with the same name instead") abstract val InsertStatement.asObject: ObjectType - abstract val selectByIds: SqlExpressionBuilder.(List) -> Op + protected open fun InsertStatement.asObject(value: InputValueType): ObjectType = asObject + abstract val selectByIds: SqlExpressionBuilder.(List) -> Op protected abstract fun insert(value: InputValueType, it: InsertStatement) protected abstract fun update(id: IdType, value: InputValueType, it: UpdateStatement) @@ -34,7 +36,7 @@ abstract class AbstractExposedWriteCRUDRepo( protected open suspend fun onBeforeCreate(value: List) {} private fun createWithoutNotification(value: InputValueType): ObjectType { return transaction(database) { - insert { insert(value, it) }.asObject + insert { insert(value, it) }.asObject(value) } } @@ -42,10 +44,8 @@ abstract class AbstractExposedWriteCRUDRepo( onBeforeCreate(values) return transaction(db = database) { values.map { value -> createWithoutNotification(value) } - }.also { - it.forEach { - newObjectsChannel.emit(it) - } + }.onEach { + newObjectsChannel.emit(it) } } @@ -83,13 +83,9 @@ abstract class AbstractExposedWriteCRUDRepo( return ( transaction(db = database) { values.map { (id, value) -> updateWithoutNotification(id, value) } - }.filter { - it != null - } as List - ).also { - it.forEach { - updateObjectsChannel.emit(it) - } + }.filterNotNull() + ).onEach { + updateObjectsChannel.emit(it) } } protected open suspend fun onBeforeDelete(ids: List) {}