com.sxtanna.database.struct.obj.SqlProperty.kt Maven / Gradle / Ivy
package com.sxtanna.database.struct.obj
import com.sxtanna.database.ext.VARCHAR_SIZE
import com.sxtanna.database.struct.SqlType
import com.sxtanna.database.struct.SqlType.*
import com.sxtanna.database.struct.SqlType.EnumSet
import com.sxtanna.database.struct.obj.base.*
import java.sql.Timestamp
import java.util.*
import kotlin.Byte
import kotlin.Double
import kotlin.Enum
import kotlin.Float
import kotlin.Int
import kotlin.Long
import kotlin.Short
import kotlin.String
import kotlin.reflect.KClass
import kotlin.reflect.KProperty1
import kotlin.reflect.full.findAnnotation
import kotlin.reflect.jvm.jvmErasure
@Suppress("UNCHECKED_CAST")
object SqlProperty {
private val adapters = mutableMapOf, KProperty1<*, *>.() -> SqlType>()
private val fallback : KProperty1<*, *>.() -> SqlType = { VarChar(VARCHAR_SIZE, isPrimaryKey(), isNotNull()) }
init {
adapters[Boolean::class] = { Bool(isPrimaryKey(), isNotNull()) }
adapters[Char::class] = { SqlType.Char(1, isPrimaryKey(), isNotNull()) }
adapters[UUID::class] = { SqlType.Char(36, isPrimaryKey(), isNotNull()) }
adapters[Enum::class] = {
val serialized = findAnnotation() != null
if (serialized) VarChar(VARCHAR_SIZE, isPrimaryKey(), isNotNull()) else EnumSet(returnType.jvmErasure as KClass>, isPrimaryKey(), isNotNull())
}
adapters[String::class] = { VarChar(findAnnotation()?.length ?: VARCHAR_SIZE, isPrimaryKey(), isNotNull()) }
adapters[Timestamp::class] = {
val time = findAnnotation © 2015 - 2025 Weber Informatics LLC | Privacy Policy