update : Use @Upsert from Room instead of a custom helper

Change-Id: I21194fda29976e069d5cfc1e083cf48d3dd149fe
pull/1837/head
YvesKalume 3 years ago
parent 558b979d08
commit 0390d65f03

@ -57,6 +57,10 @@ class TestAuthorDao : AuthorDao {
throw NotImplementedError("Unused in tests") throw NotImplementedError("Unused in tests")
} }
override suspend fun upsertAuthors(entities: List<AuthorEntity>) {
TODO("Not yet implemented")
}
override suspend fun deleteAuthors(ids: List<String>) { override suspend fun deleteAuthors(ids: List<String>) {
val idSet = ids.toSet() val idSet = ids.toSet()
entitiesStateFlow.update { entities -> entitiesStateFlow.update { entities ->

@ -85,6 +85,10 @@ class TestNewsResourceDao : NewsResourceDao {
throw NotImplementedError("Unused in tests") throw NotImplementedError("Unused in tests")
} }
override suspend fun upsertNewsResources(newsResourceEntities: List<NewsResourceEntity>) {
TODO("Not yet implemented")
}
override suspend fun insertOrIgnoreTopicCrossRefEntities( override suspend fun insertOrIgnoreTopicCrossRefEntities(
newsResourceTopicCrossReferences: List<NewsResourceTopicCrossRef> newsResourceTopicCrossReferences: List<NewsResourceTopicCrossRef>
) { ) {

@ -62,6 +62,10 @@ class TestTopicDao : TopicDao {
throw NotImplementedError("Unused in tests") throw NotImplementedError("Unused in tests")
} }
override suspend fun upsertTopics(entities: List<TopicEntity>) {
TODO("Not yet implemented")
}
override suspend fun deleteTopics(ids: List<String>) { override suspend fun deleteTopics(ids: List<String>) {
val idSet = ids.toSet() val idSet = ids.toSet()
entitiesStateFlow.update { entities -> entitiesStateFlow.update { entities ->

@ -20,8 +20,8 @@ import androidx.room.Dao
import androidx.room.Insert import androidx.room.Insert
import androidx.room.OnConflictStrategy import androidx.room.OnConflictStrategy
import androidx.room.Query import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update import androidx.room.Update
import androidx.room.Upsert
import com.google.samples.apps.nowinandroid.core.database.model.AuthorEntity import com.google.samples.apps.nowinandroid.core.database.model.AuthorEntity
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
@ -56,12 +56,8 @@ interface AuthorDao {
/** /**
* Inserts or updates [entities] in the db under the specified primary keys * Inserts or updates [entities] in the db under the specified primary keys
*/ */
@Transaction @Upsert
suspend fun upsertAuthors(entities: List<AuthorEntity>) = upsert( suspend fun upsertAuthors(entities: List<AuthorEntity>)
items = entities,
insertMany = ::insertOrIgnoreAuthors,
updateMany = ::updateAuthors
)
/** /**
* Deletes rows in the db matching the specified [ids] * Deletes rows in the db matching the specified [ids]

@ -22,6 +22,7 @@ import androidx.room.OnConflictStrategy
import androidx.room.Query import androidx.room.Query
import androidx.room.Transaction import androidx.room.Transaction
import androidx.room.Update import androidx.room.Update
import androidx.room.Upsert
import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceAuthorCrossRef import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceAuthorCrossRef
import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceEntity import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceEntity
import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceTopicCrossRef import com.google.samples.apps.nowinandroid.core.database.model.NewsResourceTopicCrossRef
@ -80,12 +81,8 @@ interface NewsResourceDao {
/** /**
* Inserts or updates [newsResourceEntities] in the db under the specified primary keys * Inserts or updates [newsResourceEntities] in the db under the specified primary keys
*/ */
@Transaction @Upsert
suspend fun upsertNewsResources(newsResourceEntities: List<NewsResourceEntity>) = upsert( suspend fun upsertNewsResources(newsResourceEntities: List<NewsResourceEntity>)
items = newsResourceEntities,
insertMany = ::insertOrIgnoreNewsResources,
updateMany = ::updateNewsResources
)
@Insert(onConflict = OnConflictStrategy.IGNORE) @Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun insertOrIgnoreTopicCrossRefEntities( suspend fun insertOrIgnoreTopicCrossRefEntities(

@ -20,8 +20,8 @@ import androidx.room.Dao
import androidx.room.Insert import androidx.room.Insert
import androidx.room.OnConflictStrategy import androidx.room.OnConflictStrategy
import androidx.room.Query import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update import androidx.room.Update
import androidx.room.Upsert
import com.google.samples.apps.nowinandroid.core.database.model.TopicEntity import com.google.samples.apps.nowinandroid.core.database.model.TopicEntity
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
@ -64,12 +64,8 @@ interface TopicDao {
/** /**
* Inserts or updates [entities] in the db under the specified primary keys * Inserts or updates [entities] in the db under the specified primary keys
*/ */
@Transaction @Upsert
suspend fun upsertTopics(entities: List<TopicEntity>) = upsert( suspend fun upsertTopics(entities: List<TopicEntity>)
items = entities,
insertMany = ::insertOrIgnoreTopics,
updateMany = ::updateTopics
)
/** /**
* Deletes rows in the db matching the specified [ids] * Deletes rows in the db matching the specified [ids]

@ -45,7 +45,7 @@ protobuf = "3.21.5"
protobufPlugin = "0.8.19" protobufPlugin = "0.8.19"
retrofit = "2.9.0" retrofit = "2.9.0"
retrofitKotlinxSerializationJson = "0.8.0" retrofitKotlinxSerializationJson = "0.8.0"
room = "2.4.3" room = "2.5.0-alpha03"
secrets = "2.0.1" secrets = "2.0.1"
turbine = "0.8.0" turbine = "0.8.0"

Loading…
Cancel
Save