com.lightningkite.ktordb.signal2.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of db Show documentation
Show all versions of db Show documentation
An abstract tool for communicating with different types of databases.
The newest version!
package com.lightningkite.ktordb
inline fun FieldCollection.interceptCreate(crossinline interceptor: suspend (Model) -> Model): FieldCollection =
object : FieldCollection by this {
override val wraps = this@interceptCreate
override suspend fun insert(models: List): List =
wraps.insertMany(models.map { interceptor(it) })
override suspend fun upsertOne(
condition: Condition,
modification: Modification,
model: Model
): EntryChange = wraps.upsertOne(condition, modification, interceptor(model))
override suspend fun upsertOneIgnoringResult(
condition: Condition,
modification: Modification,
model: Model
): Boolean = wraps.upsertOneIgnoringResult(condition, modification, interceptor(model))
}
inline fun FieldCollection.interceptReplace(crossinline interceptor: suspend (Model) -> Model): FieldCollection =
object : FieldCollection by this {
override val wraps = this@interceptReplace
override suspend fun upsertOne(
condition: Condition,
modification: Modification,
model: Model
): EntryChange = wraps.upsertOne(condition, modification, interceptor(model))
override suspend fun upsertOneIgnoringResult(
condition: Condition,
modification: Modification,
model: Model
): Boolean = wraps.upsertOneIgnoringResult(condition, modification, interceptor(model))
override suspend fun replaceOne(condition: Condition, model: Model): EntryChange =
wraps.replaceOne(
condition,
interceptor(model)
)
override suspend fun replaceOneIgnoringResult(condition: Condition, model: Model): Boolean =
wraps.replaceOneIgnoringResult(
condition,
interceptor(model)
)
}
inline fun FieldCollection.interceptModification(crossinline interceptor: suspend (Modification) -> Modification): FieldCollection =
object : FieldCollection by this {
override val wraps = this@interceptModification
override suspend fun upsertOne(
condition: Condition,
modification: Modification,
model: Model
): EntryChange = wraps.upsertOne(condition, interceptor(modification), model)
override suspend fun upsertOneIgnoringResult(
condition: Condition,
modification: Modification,
model: Model
): Boolean = wraps.upsertOneIgnoringResult(condition, interceptor(modification), model)
override suspend fun updateOne(
condition: Condition,
modification: Modification
): EntryChange = wraps.updateOne(condition, interceptor(modification))
override suspend fun updateOneIgnoringResult(
condition: Condition,
modification: Modification
): Boolean = wraps.updateOneIgnoringResult(condition, interceptor(modification))
override suspend fun updateMany(
condition: Condition,
modification: Modification
): CollectionChanges = wraps.updateMany(condition, interceptor(modification))
override suspend fun updateManyIgnoringResult(
condition: Condition,
modification: Modification
): Int = wraps.updateManyIgnoringResult(condition, interceptor(modification))
}