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

Change-Id: I21194fda29976e069d5cfc1e083cf48d3dd149fe
pull/311/head
YvesKalume 2 years ago
parent f68a112cfe
commit d094e96a72

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

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

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

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

@ -22,6 +22,7 @@ import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
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.NewsResourceEntity
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
*/
@Transaction
suspend fun upsertNewsResources(newsResourceEntities: List<NewsResourceEntity>) = upsert(
items = newsResourceEntities,
insertMany = ::insertOrIgnoreNewsResources,
updateMany = ::updateNewsResources
)
@Upsert
suspend fun upsertNewsResources(newsResourceEntities: List<NewsResourceEntity>)
@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun insertOrIgnoreTopicCrossRefEntities(

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

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

Loading…
Cancel
Save