Update room version

This commit is contained in:
vfsfitvnm 2022-08-30 10:54:33 +02:00
parent c94d05cd90
commit 14a0577d51
3 changed files with 23 additions and 34 deletions

View file

@ -23,6 +23,7 @@ import androidx.room.Transaction
import androidx.room.TypeConverter import androidx.room.TypeConverter
import androidx.room.TypeConverters import androidx.room.TypeConverters
import androidx.room.Update import androidx.room.Update
import androidx.room.Upsert
import androidx.room.migration.AutoMigrationSpec import androidx.room.migration.AutoMigrationSpec
import androidx.room.migration.Migration import androidx.room.migration.Migration
import androidx.sqlite.db.SimpleSQLiteQuery import androidx.sqlite.db.SimpleSQLiteQuery
@ -310,6 +311,15 @@ interface Database {
@Update @Update
fun update(playlist: Playlist) fun update(playlist: Playlist)
@Upsert
fun upsert(album: Album, songAlbumMaps: List<SongAlbumMap>)
@Upsert
fun upsert(songAlbumMap: SongAlbumMap)
@Upsert
fun upsert(artist: Artist)
@Delete @Delete
fun delete(searchQuery: SearchQuery) fun delete(searchQuery: SearchQuery)
@ -321,24 +331,6 @@ interface Database {
@Delete @Delete
fun delete(songPlaylistMap: SongPlaylistMap) fun delete(songPlaylistMap: SongPlaylistMap)
fun upsert(songAlbumMap: SongAlbumMap) {
if (insert(songAlbumMap) == -1L) {
update(songAlbumMap)
}
}
fun upsert(artist: Artist) {
if (insert(artist) == -1L) {
update(artist)
}
}
fun upsert(album: Album) {
if (insert(album) == -1L) {
update(album)
}
}
} }
@androidx.room.Database( @androidx.room.Database(
@ -540,19 +532,19 @@ object Converters {
val Database.internal: RoomDatabase val Database.internal: RoomDatabase
get() = DatabaseInitializer.Instance get() = DatabaseInitializer.Instance
fun query(block: () -> Unit) = DatabaseInitializer.Instance.getQueryExecutor().execute(block) fun query(block: () -> Unit) = DatabaseInitializer.Instance.queryExecutor.execute(block)
fun transaction(block: () -> Unit) = with(DatabaseInitializer.Instance) { fun transaction(block: () -> Unit) = with(DatabaseInitializer.Instance) {
getTransactionExecutor().execute { transactionExecutor.execute {
runInTransaction(block) runInTransaction(block)
} }
} }
val RoomDatabase.path: String val RoomDatabase.path: String?
get() = getOpenHelper().writableDatabase.path get() = openHelper.writableDatabase.path
fun RoomDatabase.checkpoint() { fun RoomDatabase.checkpoint() {
getOpenHelper().writableDatabase.run { openHelper.writableDatabase.run {
query("PRAGMA journal_mode").use { cursor -> query("PRAGMA journal_mode").use { cursor ->
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
when (cursor.getString(0).lowercase()) { when (cursor.getString(0).lowercase()) {

View file

@ -98,21 +98,18 @@ fun AlbumScreen(browseId: String) {
authorsText = youtubeAlbum.authors?.joinToString("") { it.name }, authorsText = youtubeAlbum.authors?.joinToString("") { it.name },
shareUrl = youtubeAlbum.url, shareUrl = youtubeAlbum.url,
timestamp = System.currentTimeMillis() timestamp = System.currentTimeMillis()
) ),
) youtubeAlbum.items?.mapIndexedNotNull { position, albumItem ->
youtubeAlbum.items?.forEachIndexed { position, albumItem ->
albumItem.toMediaItem(browseId, youtubeAlbum)?.let { mediaItem -> albumItem.toMediaItem(browseId, youtubeAlbum)?.let { mediaItem ->
Database.insert(mediaItem) Database.insert(mediaItem)
Database.upsert(
SongAlbumMap( SongAlbumMap(
songId = mediaItem.mediaId, songId = mediaItem.mediaId,
albumId = browseId, albumId = browseId,
position = position position = position
) )
}
} ?: emptyList()
) )
}
}
null null
} }

View file

@ -29,7 +29,7 @@ dependencyResolutionManagement {
library("compose-coil", "io.coil-kt", "coil-compose").version("2.2.0") library("compose-coil", "io.coil-kt", "coil-compose").version("2.2.0")
version("room", "2.5.0-alpha02") version("room", "2.5.0-alpha03")
library("room", "androidx.room", "room-ktx").versionRef("room") library("room", "androidx.room", "room-ktx").versionRef("room")
library("room-compiler", "androidx.room", "room-compiler").versionRef("room") library("room-compiler", "androidx.room", "room-compiler").versionRef("room")