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

com.sxtanna.database.task.builder.InsertBuilder.kt Maven / Gradle / Ivy

There is a newer version: 3.0-beta
Show newest version
package com.sxtanna.database.task.builder

import com.sxtanna.database.ext.PrimaryKey
import com.sxtanna.database.type.base.SqlObject
import kotlin.reflect.KClass
import kotlin.reflect.full.findAnnotation
import kotlin.reflect.full.memberProperties

class InsertBuilder(val clazz : KClass, val table : String) {

	var ignore = false
		private set
	var update = emptyArray()
		private set


	fun onDupeIgnore() : InsertBuilder {
		ignore = true
		return this
	}

	@JvmOverloads
	fun onDupeUpdate(vararg column : CharSequence = arrayOf(clazz.memberProperties.find { it.findAnnotation() != null }?.name ?: "")) : InsertBuilder {
		update = column.map { it.toString() }.toTypedArray()
		return this
	}


	companion object Insert {

		@JvmSynthetic
		inline fun  into(table : String = T::class.simpleName!!) = InsertBuilder(T::class, table)

		@JvmOverloads
		fun  into(clazz : Class, table : String = clazz.simpleName!!) = InsertBuilder(clazz.kotlin, table)

	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy