
com.sxtanna.database.task.builder.Insert.kt Maven / Gradle / Ivy
package com.sxtanna.database.task.builder
import com.sxtanna.database.ext.PrimaryKey
import com.sxtanna.database.task.builder.base.BuilderStatement
import com.sxtanna.database.type.base.SqlObject
import kotlin.reflect.KClass
import kotlin.reflect.full.findAnnotation
import kotlin.reflect.full.memberProperties
class Insert(val clazz : KClass, override val table : String) : BuilderStatement() {
var ignore = false
private set
var update = emptyArray()
private set
fun onDupeIgnore() : Insert {
ignore = true
return this
}
@JvmOverloads
fun onDupeUpdate(vararg column : CharSequence = arrayOf(clazz.memberProperties.find { it.findAnnotation() != null }?.name ?: "")) : Insert {
update = column.map { it.toString() }.toTypedArray()
return this
}
companion object {
inline fun into(table : String = T::class.simpleName!!) = Insert(T::class, table)
@JvmStatic
@JvmOverloads
fun into(clazz : Class, table : String = clazz.simpleName!!) = Insert(clazz.kotlin, table)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy