Skip to content

Commit

Permalink
refactor: add partial model classes
Browse files Browse the repository at this point in the history
  • Loading branch information
zyrouge committed Jan 19, 2025
1 parent da58f5c commit e96b81c
Show file tree
Hide file tree
Showing 49 changed files with 1,480 additions and 630 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "03822e08bb41204b4a0237835b616d5b",
"identityHash": "62b63bbc48d6e0426718cdc16623be30",
"entities": [
{
"tableName": "songs",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `title` TEXT NOT NULL, `album` TEXT, `artists` TEXT NOT NULL, `composers` TEXT NOT NULL, `albumArtists` TEXT NOT NULL, `genres` TEXT NOT NULL, `trackNumber` INTEGER, `trackTotal` INTEGER, `discNumber` INTEGER, `discTotal` INTEGER, `date` TEXT, `year` INTEGER, `duration` INTEGER NOT NULL, `bitrate` INTEGER, `samplingRate` INTEGER, `channels` INTEGER, `encoder` TEXT, `dateModified` INTEGER NOT NULL, `size` INTEGER NOT NULL, `coverFile` TEXT, `uri` TEXT NOT NULL, `path` TEXT NOT NULL, PRIMARY KEY(`id`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `title` TEXT NOT NULL, `album` TEXT, `track_number` INTEGER, `track_total` INTEGER, `disc_number` INTEGER, `disc_total` INTEGER, `date` TEXT, `year` INTEGER, `duration` INTEGER NOT NULL, `bitrate` INTEGER, `sampling_rate` INTEGER, `channels` INTEGER, `encoder` TEXT, `date_modified` INTEGER NOT NULL, `size` INTEGER NOT NULL, `cover_file` TEXT, `uri` TEXT NOT NULL, `path` TEXT NOT NULL, PRIMARY KEY(`id`), FOREIGN KEY(`id`) REFERENCES `song_files`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
Expand All @@ -21,56 +21,32 @@
"notNull": true
},
{
"fieldPath": "album",
"fieldPath": "albumId",
"columnName": "album",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "artists",
"columnName": "artists",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "composers",
"columnName": "composers",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "albumArtists",
"columnName": "albumArtists",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "genres",
"columnName": "genres",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "trackNumber",
"columnName": "trackNumber",
"columnName": "track_number",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "trackTotal",
"columnName": "trackTotal",
"columnName": "track_total",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "discNumber",
"columnName": "discNumber",
"columnName": "disc_number",
"affinity": "INTEGER",
"notNull": false
},
{
"fieldPath": "discTotal",
"columnName": "discTotal",
"columnName": "disc_total",
"affinity": "INTEGER",
"notNull": false
},
Expand Down Expand Up @@ -100,7 +76,7 @@
},
{
"fieldPath": "samplingRate",
"columnName": "samplingRate",
"columnName": "sampling_rate",
"affinity": "INTEGER",
"notNull": false
},
Expand All @@ -118,7 +94,7 @@
},
{
"fieldPath": "dateModified",
"columnName": "dateModified",
"columnName": "date_modified",
"affinity": "INTEGER",
"notNull": true
},
Expand All @@ -130,7 +106,7 @@
},
{
"fieldPath": "coverFile",
"columnName": "coverFile",
"columnName": "cover_file",
"affinity": "TEXT",
"notNull": false
},
Expand All @@ -154,13 +130,25 @@
]
},
"indices": [],
"foreignKeys": []
"foreignKeys": [
{
"table": "song_files",
"onDelete": "CASCADE",
"onUpdate": "NO ACTION",
"columns": [
"id"
],
"referencedColumns": [
"id"
]
}
]
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '03822e08bb41204b4a0237835b616d5b')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '62b63bbc48d6e0426718cdc16623be30')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "6091615e6ae35543e127d6744215fad8",
"identityHash": "911e8d9ac1e9715396e1465009d548b3",
"entities": [
{
"tableName": "playlists",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `title` TEXT NOT NULL, `songPaths` TEXT NOT NULL, `uri` TEXT, `path` TEXT, PRIMARY KEY(`id`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `title` TEXT NOT NULL, `songPaths` TEXT NOT NULL, `title` TEXT, `path` TEXT, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
Expand All @@ -28,7 +28,7 @@
},
{
"fieldPath": "uri",
"columnName": "uri",
"columnName": "title",
"affinity": "TEXT",
"notNull": false
},
Expand All @@ -52,7 +52,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '6091615e6ae35543e127d6744215fad8')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '911e8d9ac1e9715396e1465009d548b3')"
]
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,45 @@
package io.github.zyrouge.symphony.services.database

import io.github.zyrouge.symphony.Symphony
import io.github.zyrouge.symphony.services.database.store.ArtworkCacheStore
import io.github.zyrouge.symphony.services.database.store.LyricsCacheStore
import io.github.zyrouge.symphony.services.database.store.ArtworkStore
import io.github.zyrouge.symphony.utils.KeyGenerator

class Database(symphony: Symphony) {
private val cache = CacheDatabase.create(symphony)
private val persistent = PersistentDatabase.create(symphony)

val artworkCache = ArtworkCacheStore(symphony)
val lyricsCache = LyricsCacheStore(symphony)
val songCache get() = cache.songs()
val albumArtistSongsIdGenerator = KeyGenerator.TimeIncremental()
val albumArtistsIdGenerator = KeyGenerator.TimeIncremental()
val albumSongsIdGenerator = KeyGenerator.TimeIncremental()
val albumsIdGenerator = KeyGenerator.TimeIncremental()
val artistSongsIdGenerator = KeyGenerator.TimeIncremental()
val artistsIdGenerator = KeyGenerator.TimeIncremental()
val mediaTreeFoldersIdGenerator = KeyGenerator.TimeIncremental()
val mediaTreeSongFilesIdGenerator = KeyGenerator.TimeIncremental()
val mediaTreeLyricsFilesIdGenerator = KeyGenerator.TimeIncremental()
val genreSongsIdGenerator = KeyGenerator.TimeIncremental()
val genreIdGenerator = KeyGenerator.TimeIncremental()
val playlistSongsIdGenerator = KeyGenerator.TimeIncremental()
val playlistsIdGenerator = KeyGenerator.TimeIncremental()
val songFilesIdGenerator = KeyGenerator.TimeIncremental()
val songLyricsIdGenerator = KeyGenerator.TimeIncremental()
val songsIdGenerator = KeyGenerator.TimeIncremental()

val albumArtistSongs get() = persistent.albumArtistSongs()
val albumArtists get() = persistent.albumArtists()
val albumSongs get() = persistent.albumSongs()
val albums get() = persistent.albums()
val artistSongs get() = persistent.artistSongs()
val artists get() = persistent.artists()
val artwork = ArtworkStore(symphony)
val artworkIndices get() = persistent.artworkIndices()
val genreSongs get() = persistent.genreSongs()
val genre get() = persistent.genre()
val mediaTreeFolders get() = persistent.mediaTreeFolders()
val mediaTreeSongFiles get() = persistent.mediaTreeSongFiles()
val mediaTreeLyricsFiles get() = persistent.mediaTreeLyricsFiles()
val playlistSongs get() = persistent.playlistSongs()
val playlists get() = persistent.playlists()
val songFiles get() = persistent.songFiles()
val songLyrics get() = persistent.songLyrics()
val songs get() = persistent.songs()
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,85 @@ import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import io.github.zyrouge.symphony.Symphony
import io.github.zyrouge.symphony.services.database.store.AlbumArtistMappingStore
import io.github.zyrouge.symphony.services.database.store.AlbumSongMappingStore
import io.github.zyrouge.symphony.services.database.store.AlbumStore
import io.github.zyrouge.symphony.services.database.store.ArtistSongMappingStore
import io.github.zyrouge.symphony.services.database.store.ArtistStore
import io.github.zyrouge.symphony.services.database.store.ArtworkIndexStore
import io.github.zyrouge.symphony.services.database.store.GenreSongMappingStore
import io.github.zyrouge.symphony.services.database.store.GenreStore
import io.github.zyrouge.symphony.services.database.store.MediaTreeFolderStore
import io.github.zyrouge.symphony.services.database.store.MediaTreeLyricsFileStore
import io.github.zyrouge.symphony.services.database.store.MediaTreeSongFileStore
import io.github.zyrouge.symphony.services.database.store.PlaylistSongMappingStore
import io.github.zyrouge.symphony.services.database.store.PlaylistStore
import io.github.zyrouge.symphony.services.groove.Playlist
import io.github.zyrouge.symphony.services.database.store.SongFileStore
import io.github.zyrouge.symphony.services.database.store.SongLyricsStore
import io.github.zyrouge.symphony.services.database.store.SongStore
import io.github.zyrouge.symphony.services.groove.entities.Album
import io.github.zyrouge.symphony.services.groove.entities.AlbumArtistMapping
import io.github.zyrouge.symphony.services.groove.entities.AlbumSongMapping
import io.github.zyrouge.symphony.services.groove.entities.Artist
import io.github.zyrouge.symphony.services.groove.entities.ArtistSongMapping
import io.github.zyrouge.symphony.services.groove.entities.ArtworkIndex
import io.github.zyrouge.symphony.services.groove.entities.Genre
import io.github.zyrouge.symphony.services.groove.entities.GenreSongMapping
import io.github.zyrouge.symphony.services.groove.entities.Playlist
import io.github.zyrouge.symphony.services.groove.entities.PlaylistSongMapping
import io.github.zyrouge.symphony.services.groove.entities.Song
import io.github.zyrouge.symphony.services.groove.entities.SongFile
import io.github.zyrouge.symphony.services.groove.entities.SongLyrics
import io.github.zyrouge.symphony.utils.RoomConvertors

@Database(entities = [Playlist::class], version = 1)
@Database(
version = 1,
entities = [
AlbumArtistMapping::class,
AlbumSongMapping::class,
Album::class,
ArtistSongMapping::class,
Artist::class,
ArtworkIndex::class,
GenreSongMapping::class,
Genre::class,
MediaTreeFolderStore::class,
MediaTreeLyricsFileStore::class,
MediaTreeSongFileStore::class,
PlaylistSongMapping::class,
Playlist::class,
SongFile::class,
SongLyrics::class,
Song::class,
],
)
@TypeConverters(RoomConvertors::class)
abstract class PersistentDatabase : RoomDatabase() {
abstract fun albumArtistMapping(): AlbumArtistMappingStore
abstract fun albumSongMapping(): AlbumSongMappingStore
abstract fun albums(): AlbumStore
abstract fun artistSongMapping(): ArtistSongMappingStore
abstract fun artists(): ArtistStore
abstract fun artworkIndices(): ArtworkIndexStore
abstract fun genreSongMapping(): GenreSongMappingStore
abstract fun genre(): GenreStore
abstract fun mediaTreeFolders(): MediaTreeFolderStore
abstract fun mediaTreeSongFiles(): MediaTreeSongFileStore
abstract fun mediaTreeLyricsFiles(): MediaTreeLyricsFileStore
abstract fun playlistSongMapping(): PlaylistSongMappingStore
abstract fun playlists(): PlaylistStore
abstract fun songFiles(): SongFileStore
abstract fun songLyrics(): SongLyricsStore
abstract fun songs(): SongStore

companion object {
const val DATABASE_NAME = "symphony_persistent"

fun create(symphony: Symphony) = Room
.databaseBuilder(
symphony.applicationContext,
PersistentDatabase::class.java,
"persistent"
DATABASE_NAME
)
.build()
}
Expand Down
Loading

0 comments on commit e96b81c

Please sign in to comment.