com.sxtanna.db.struct.Table.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Kuery Show documentation
Show all versions of Kuery Show documentation
MySQL Kotlin DSL/ORM based on HikariCP
package com.sxtanna.db.struct
import com.sxtanna.db.type.Named
import kotlin.reflect.KClass
import kotlin.reflect.KProperty1
import kotlin.reflect.jvm.jvmName
import kotlin.reflect.jvm.kotlinProperty
class Table @PublishedApi internal constructor(val clazz : KClass) : Named {
override val name = clazz.simpleName ?: clazz.jvmName
internal val fields by lazy {
clazz.java.declaredFields
.filter { it.getAnnotation(Transient::class.java) == null }
.mapNotNull { it.kotlinProperty as? KProperty1 }
}
internal val columns = mutableMapOf()
init {
fields.forEach {
columns[it.name] = Resolver.SqlO[it]
}
}
override fun equals(other : Any?) : Boolean {
if (this === other) return true
if (other !is Table<*>) return false
if (clazz != other.clazz) return false
if (columns != other.columns) return false
return true
}
override fun hashCode() : Int {
var result = clazz.hashCode()
result = 31 * result + columns.hashCode()
return result
}
companion object {
inline fun of() = Table(T::class)
}
}