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