com.lightningkite.lightningserver.db.ModelInfo.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of server-core Show documentation
Show all versions of server-core Show documentation
A set of tools to fill in/replace what Ktor is lacking in.
The newest version!
package com.lightningkite.lightningserver.db
import com.lightningkite.lightningdb.FieldCollection
import com.lightningkite.lightningdb.HasId
import kotlinx.serialization.serializer
inline fun , reified ID : Comparable> ModelInfo(
crossinline getCollection: () -> FieldCollection,
crossinline forUser: suspend FieldCollection.(principal: USER) -> FieldCollection,
modelName: String = serializer().descriptor.serialName.substringBefore('<').substringAfterLast('.')
) = object : ModelInfo {
override fun collection(): FieldCollection = getCollection()
override suspend fun collection(principal: USER): FieldCollection =
this.collection().forUser(principal)
override val serialization: ModelSerializationInfo = ModelSerializationInfo()
override val collectionName: String = modelName
}
fun , ID : Comparable> ModelInfo(
serialization: ModelSerializationInfo,
getCollection: () -> FieldCollection,
forUser: suspend FieldCollection.(principal: USER) -> FieldCollection,
modelName: String = serialization.serializer.descriptor.serialName.substringBefore('<').substringAfterLast('.')
) = object : ModelInfo {
override val serialization: ModelSerializationInfo = serialization
override fun collection(): FieldCollection = getCollection()
override suspend fun collection(principal: USER): FieldCollection =
this.collection().forUser(principal)
override val collectionName: String = modelName
}
interface ModelInfo, ID : Comparable> {
val serialization: ModelSerializationInfo
val collectionName: String
get() = serialization.serializer.descriptor.serialName.substringBefore('<').substringAfterLast('.')
fun collection(): FieldCollection
suspend fun collection(principal: USER): FieldCollection
}