Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
Update Room version. Replace Insert with Upsert at PlantDao.
Browse files Browse the repository at this point in the history
  • Loading branch information
Keworker committed Aug 2, 2023
1 parent baf2486 commit 3c229e0
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GardenPlantingDaoTest {
database = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java).build()
gardenPlantingDao = database.gardenPlantingDao()

database.plantDao().insertAll(testPlants)
database.plantDao().upsertAll(testPlants)
testGardenPlantingId = gardenPlantingDao.insertGardenPlanting(testGardenPlanting)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PlantDaoTest {
plantDao = database.plantDao()

// Insert plants in non-alphabetical order to test that results are sorted by name
plantDao.insertAll(listOf(plantB, plantC, plantA))
plantDao.upsertAll(listOf(plantB, plantC, plantA))
}

@After fun closeDb() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
package com.google.samples.apps.sunflower.data

import androidx.room.Dao
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Upsert
import kotlinx.coroutines.flow.Flow

/**
Expand All @@ -36,6 +35,6 @@ interface PlantDao {
@Query("SELECT * FROM plants WHERE id = :plantId")
fun getPlant(plantId: String): Flow<Plant>

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertAll(plants: List<Plant>)
@Upsert
suspend fun upsertAll(plants: List<Plant>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SeedDatabaseWorker(
val plantList: List<Plant> = Gson().fromJson(jsonReader, plantType)

val database = AppDatabase.getInstance(applicationContext)
database.plantDao().insertAll(plantList)
database.plantDao().upsertAll(plantList)

Result.success()
}
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pagingCompose = "1.0.0-alpha18"
profileInstaller = "1.2.0"
recyclerView = "1.3.0-alpha02"
retrofit = "2.9.0"
room = "2.4.3"
room = "2.5.2"
runner = "1.0.1"
# @keep
targetSdk = "33"
Expand Down

0 comments on commit 3c229e0

Please sign in to comment.