com.lightningkite.ktordb.FieldCollection.ext.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
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.toList
suspend fun
FieldCollection.all() = find(condition = Condition.Always())
suspend fun
FieldCollection.findOne(condition: Condition): Model? =
find(condition = condition, limit = 1).firstOrNull()
suspend fun
FieldCollection.insertOne(model: Model): Model? = insert(listOf(model)).firstOrNull()
suspend fun
FieldCollection.insertMany(models: List): List = insert(models)
suspend fun
FieldCollection.updateManyIgnoringResult(
mass: MassModification
) = updateManyIgnoringResult(mass.condition, mass.modification)
suspend fun , ID : Comparable>
FieldCollection.updateOneByIdIgnoringResult(
id: ID,
modification: Modification
): Boolean {
return updateOneIgnoringResult(Condition.OnField(HasIdFields._id(), Condition.Equal(id)), modification)
}
suspend fun , ID : Comparable>
FieldCollection.updateOneById(
id: ID,
modification: Modification
): EntryChange {
return updateOne(Condition.OnField(HasIdFields._id(), Condition.Equal(id)), modification)
}
suspend fun , ID : Comparable>
FieldCollection.deleteOneById(
id: ID
): Boolean {
return deleteOneIgnoringOld(Condition.OnField(HasIdFields._id(), Condition.Equal(id)))
}
suspend fun , ID : Comparable>
FieldCollection.replaceOneById(
id: ID,
model: Model
) = replaceOne(Condition.OnField(HasIdFields._id(), Condition.Equal(id)), model)
suspend fun , ID : Comparable>
FieldCollection.upsertOneById(
id: ID,
model: Model
) = upsertOne(Condition.OnField(HasIdFields._id(), Condition.Equal(id)), Modification.Assign(model), model)
suspend fun , ID : Comparable>
FieldCollection.get(
id: ID
): Model? {
return find(Condition.OnField(HasIdFields._id(), Condition.Equal(id)), limit = 1).firstOrNull()
}
suspend fun , ID : Comparable>
FieldCollection.getMany(
ids: List
): List {
return find(Condition.OnField(HasIdFields._id(), Condition.Inside(ids))).toList()
}
suspend fun
FieldCollection.query(query: Query): Flow =
find(query.condition, query.orderBy, query.skip, query.limit)