All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lightningkite.ktordb.FieldCollection.ext.kt Maven / Gradle / Ivy

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)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy