Add Artist upsert
This commit is contained in:
parent
932314f8d2
commit
e6155b428c
2 changed files with 8 additions and 5 deletions
|
@ -26,7 +26,7 @@ interface Database {
|
|||
fun insert(searchQuery: SearchQuery)
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insert(info: Artist)
|
||||
fun insert(info: Artist): Long
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insert(info: Album): Long
|
||||
|
@ -40,9 +40,6 @@ interface Database {
|
|||
@Insert(onConflict = OnConflictStrategy.IGNORE)
|
||||
fun insert(songAlbumMap: SongAlbumMap): Long
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.ABORT)
|
||||
fun insert(info: List<Artist>): List<Long>
|
||||
|
||||
@Query("SELECT * FROM Song WHERE id = :id")
|
||||
fun songFlow(id: String): Flow<Song?>
|
||||
|
||||
|
@ -108,6 +105,12 @@ interface Database {
|
|||
@Update
|
||||
fun update(artist: Artist)
|
||||
|
||||
fun upsert(artist: Artist) {
|
||||
if (insert(artist) == -1L) {
|
||||
update(artist)
|
||||
}
|
||||
}
|
||||
|
||||
@Update
|
||||
fun update(album: Album)
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ fun ArtistScreen(
|
|||
shufflePlaylistId = youtubeArtist.shuffleEndpoint?.playlistId,
|
||||
radioVideoId = youtubeArtist.radioEndpoint?.videoId,
|
||||
radioPlaylistId = youtubeArtist.radioEndpoint?.playlistId,
|
||||
).also(Database::update)
|
||||
).also(Database::upsert)
|
||||
}
|
||||
}.distinctUntilChanged()
|
||||
}.collectAsState(initial = null, context = Dispatchers.IO)
|
||||
|
|
Loading…
Reference in a new issue