Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kotlin Exposed - How to insert if not exists, and on conflict?

I've looked around but cannot seem to find how in the world to 'insert if not exists' or 'insert on conflict' using the Exposed SQL framework for Kotlin. I am currently writing raw SQL statements and executing them as is. I don't think I can avoid that for some cases, but I would much rather use the framework if possible. I don't see any options for either DSL or DAO syntaxs.

Edit:

For anyone that may come across this, Tapac's comment worked for me.

Use Table.insertIgnore() for 'insert if not exists', and an example for upsert exists at https://github.com/JetBrains/Exposed/wiki/FAQ#q-is-upsert-supported.

like image 259
Dev909 Avatar asked Jul 03 '18 15:07

Dev909


1 Answers

You can try to use Table.insertIgnore for 'insert if not exists' and upsert (github.com/JetBrains/Exposed/wiki/FAQ#q-is-upsert-supported) for 'insert on conflict' .

like image 74
Tapac Avatar answered Sep 20 '22 20:09

Tapac