The problem is that update is always called, but the database is empty at that moment and nothing happens:
val existingId = saveStateRepo.getSavedId(cardId)
if (existingId == null) {
saveStateRepo.saveState(newSave)
Log.d(TAG, "ID was not yet included, included it now")
} else {
saveStateRepo.updateState(newSave)
Log.d(TAG, "ID was already included, updated it now")
}
A function is called to retrieve existingId:
@Query("SELECT * FROM saveStateDex WHERE cardID = :id LIMIT 1")
fun getSavedId(id: Int): Flow<SaveStateDex>?
It is necessary to change to the correct type SaveStateDex? or use @Insert(onConflict = OnConflictStrategy.REPLACE), then there is no need for such a function getSavedId() and @Update.