commonMain.org.kodein.db.impl.DBReadModule.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kodein-db Show documentation
Show all versions of kodein-db Show documentation
Kodein-DB implementation library
The newest version!
package org.kodein.db.impl
import org.kodein.db.*
import org.kodein.db.model.ModelRead
import kotlin.reflect.KClass
internal interface DBReadModule : DBRead {
val mdb: ModelRead
@Suppress("ReplaceGetOrSet")
override fun get(type: KClass, key: Key, vararg options: Options.Get): M? = mdb.get(type, key, *options)?.model
override fun findAll(vararg options: Options.Find): Cursor<*> = CursorImpl(mdb.findAll(*options))
override fun find(type: KClass, vararg options: Options.Find): DBRead.FindDsl = FindDslImpl(mdb, type, options)
override fun getIndexesOf(key: Key<*>): Set = mdb.getIndexesOf(key)
class FindDslImpl(private val mdb: ModelRead, private val type: KClass, private val options: Array) : DBRead.FindDsl {
override fun byId(vararg id: Any, isOpen: Boolean): Cursor =
CursorImpl(if (id.isEmpty()) mdb.findAllByType(type, *options) else mdb.findById(type, id, isOpen, *options))
override fun byIndex(index: String, vararg value: Any, isOpen: Boolean): Cursor =
CursorImpl(if (value.isEmpty()) mdb.findAllByIndex(type, index, *options) else mdb.findByIndex(type, index, value, isOpen, *options))
}
}