https://kotlinlang.org logo
#android
Title
# android
c

CamilleBC

01/15/2019, 2:26 PM
Hello ! I'm trying to see if there is a better way to do what I want to do. I wanted to upsert in my Room database. Is there any better way to do it than :
Copy code
@Transaction
    fun upsertAll(t: List<T>) {
        val id = insertAll(t)
        if (id.any { it == (-1).toLong() }) updateAll(t)
    }
?
stackoverflow 1
c

Caner Korkmaz

01/15/2019, 3:54 PM
This could cause a unique constraint exception if there is a field with a unique constraint and you're trying to insert with a new id. A generic upsertAll would be different imo, however we cannot provide you more information without more details on which types do you want to use this/constraints.