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

commonMain.com.bselzer.ktx.db.value.IdentifierValueConverter.kt Maven / Gradle / Ivy

The newest version!
package com.bselzer.ktx.db.value

import com.bselzer.ktx.value.identifier.Identifier
import org.kodein.db.Value
import org.kodein.db.ValueConverter

/**
 * A [ValueConverter] for using the wrapped value associated with an [Identifier].
 */
class IdentifierValueConverter : ValueConverter {
    override fun toValue(from: Any): Value? {
        if (from !is Identifier<*>) {
            return null
        }

        return when (val value = from.value) {
            is Int -> Value.of(value)
            is Long -> Value.of(value)
            is String -> Value.of(value)
            else -> null
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy