throws an exception when using H2. I'm up-to-date with exposed and h2 drivers... Am I missing anything else?
t
Tristan Blakers
09/21/2020, 1:53 AM
fwiw, I use these extension functions with Exposed. Cribbed with a modificaiton or two from a github repo. This is on Exposed 24.1, may be a better way by now
Copy code
class InsertOrIgnore<Key : Any>(
table: Table,
isIgnore: Boolean = false,
private vararg val keys: Column<*>
) : InsertStatement<Key>(table, isIgnore) {
override fun prepareSQL(transaction: Transaction): String {
val tm = TransactionManager.current()
val onConflict = "ON CONFLICT DO NOTHING"
return "${super.prepareSQL(transaction)} $onConflict"
}
}
fun <T : Table> T.insertOrIgnore(vararg keys: Column<*>, body: T.(InsertStatement<Number>) -> Unit) =
InsertOrIgnore<Number>(this, keys = keys).apply {
body(this)
execute(TransactionManager.current())
}