Hello ! I'm trying to see if there is a better way...
# android
c
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
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.