https://kotlinlang.org logo
#room
Title
# room
m

MV

12/02/2023, 11:18 PM
I have the following queries
Copy code
@Query("UPDATE account set current = 0 where current = 1")
    suspend fun removeCurrent()

    @Query("UPDATE account set current = 1 where id = :accountId")
    suspend fun setCurrent(accountId: Int)

    @Query("SELECT * FROM account where current = 1 limit 1")
    fun getCurrent(): LiveData<Account?>
I have some function observing the current account (getCurrent). The problem is when I swap between account I do,
removeCurrent(), setCurrent(acc)
. But between the calls of those two queries my livedata updates and subsequentially updates the consumers. I would like to avoid that (What I get from getCurrent: oldAcc, null, newAcc; What I want oldAcc, newAcc)
Alr solved this by making a
updateCurrent
which is transaction of those two queries
11 Views