mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-26 03:58:45 +00:00
crud exposed realization open fun asObject
This commit is contained in:
parent
490c318d1c
commit
88f2c16c82
@ -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
|
||||
|
||||
|
@ -25,8 +25,10 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
|
||||
override val updatedObjectsFlow: Flow<ObjectType> = updateObjectsChannel.asSharedFlow()
|
||||
override val deletedObjectsIdsFlow: Flow<IdType> = deleteObjectsIdsChannel.asSharedFlow()
|
||||
|
||||
@Deprecated("Will be removed in near major update. Override open fun with the same name instead")
|
||||
abstract val InsertStatement<Number>.asObject: ObjectType
|
||||
abstract val selectByIds: SqlExpressionBuilder.(List<out IdType>) -> Op<Boolean>
|
||||
protected open fun InsertStatement<Number>.asObject(value: InputValueType): ObjectType = asObject
|
||||
abstract val selectByIds: SqlExpressionBuilder.(List<IdType>) -> Op<Boolean>
|
||||
|
||||
protected abstract fun insert(value: InputValueType, it: InsertStatement<Number>)
|
||||
protected abstract fun update(id: IdType, value: InputValueType, it: UpdateStatement)
|
||||
@ -34,7 +36,7 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
|
||||
protected open suspend fun onBeforeCreate(value: List<InputValueType>) {}
|
||||
private fun createWithoutNotification(value: InputValueType): ObjectType {
|
||||
return transaction(database) {
|
||||
insert { insert(value, it) }.asObject
|
||||
insert { insert(value, it) }.asObject(value)
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,12 +44,10 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
|
||||
onBeforeCreate(values)
|
||||
return transaction(db = database) {
|
||||
values.map { value -> createWithoutNotification(value) }
|
||||
}.also {
|
||||
it.forEach {
|
||||
}.onEach {
|
||||
newObjectsChannel.emit(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected open suspend fun onBeforeUpdate(value: List<UpdatedValuePair<IdType, InputValueType>>) {}
|
||||
private fun updateWithoutNotification(id: IdType, value: InputValueType): ObjectType? {
|
||||
@ -83,15 +83,11 @@ abstract class AbstractExposedWriteCRUDRepo<ObjectType, IdType, InputValueType>(
|
||||
return (
|
||||
transaction(db = database) {
|
||||
values.map { (id, value) -> updateWithoutNotification(id, value) }
|
||||
}.filter {
|
||||
it != null
|
||||
} as List<ObjectType>
|
||||
).also {
|
||||
it.forEach {
|
||||
}.filterNotNull()
|
||||
).onEach {
|
||||
updateObjectsChannel.emit(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
protected open suspend fun onBeforeDelete(ids: List<IdType>) {}
|
||||
override suspend fun deleteById(ids: List<IdType>) {
|
||||
onBeforeDelete(ids)
|
||||
|
Loading…
Reference in New Issue
Block a user