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

View file

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

View file

@ -29,7 +29,7 @@ dependencyResolutionManagement {
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-compiler", "androidx.room", "room-compiler").versionRef("room")