.port_store.1.3.1.source-code.Store.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of port_store Show documentation
Show all versions of port_store Show documentation
The atoms of your platform
package com.hexagonkt.store
import com.hexagonkt.helpers.ensureSize
import com.hexagonkt.serialization.parseObjects
import com.hexagonkt.store.IndexOrder.ASCENDING
import java.io.File
import java.net.URL
import kotlin.reflect.KClass
import kotlin.reflect.KProperty1
/**
* TODO All methods accepting maps rely on `mapOf` returning an insertion ordered map. Take care of
* this in the future to avoid possible bugs
*/
interface Store {
val type: KClass
val key: KProperty1
val name: String
val mapper: Mapper
fun createIndex(unique: Boolean, fields: Map): String
fun createIndex(unique: Boolean, vararg fields: Pair, IndexOrder>): String =
createIndex(unique, fields.map { it.first.name to it.second }.toMap())
fun createIndex(unique: Boolean, vararg fields: KProperty1): String =
createIndex(unique, *fields.map { it to ASCENDING }.toTypedArray())
fun insertOne(instance: T): K
fun insertMany(instances: List): List
fun insertMany(vararg instances: T): List =
insertMany(instances.toList())
fun saveOne(instance: T): K? // returns key if created, null if updated
fun saveMany(instances: List): List
fun replaceOne(instance: T): Boolean
fun replaceMany(instances: List): List
fun replaceMany(vararg instances: T): List =
replaceMany(instances.toList())
fun updateOne(key: K, updates: Map): Boolean
fun updateOne(key: K, vararg updates: Pair, *>): Boolean =
updateOne(key, fields(*updates))
fun updateMany(filter: Map, updates: Map): Long
fun deleteOne(id: K): Boolean
fun deleteMany(filter: Map): Long
fun findOne(key: K): T?
fun findOne(key: K, fields: List): Map?
fun findOne(filter: Map): T? =
findMany(filter).ensureSize(0..1).firstOrNull()
fun findOne(filter: Map, fields: List): Map? =
findMany(filter, fields).ensureSize(0..1).firstOrNull()
fun findMany(
filter: Map,
limit: Int? = null,
skip: Int? = null,
sort: Map = emptyMap()): List
fun findMany(
filter: Map,
fields: List,
limit: Int? = null,
skip: Int? = null,
sort: Map = emptyMap()): List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy