added room and starting making database classes
parent
1956170e33
commit
6fcb1a7d39
@ -0,0 +1,11 @@
|
||||
package usr.empty.player.database
|
||||
|
||||
import androidx.room.Database
|
||||
import androidx.room.RoomDatabase
|
||||
|
||||
@Database(
|
||||
entities = [Track::class], version = 1
|
||||
)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
abstract fun trackDao(): TrackDao
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package usr.empty.player.database
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Insert
|
||||
import androidx.room.PrimaryKey
|
||||
import androidx.room.Query
|
||||
import usr.empty.player.NotaDescriptor
|
||||
import java.util.UUID
|
||||
|
||||
// a.k.a. Nota
|
||||
@Entity
|
||||
data class Track(
|
||||
@ColumnInfo val title: String,
|
||||
@ColumnInfo val artistId: Int,
|
||||
@ColumnInfo val albumId: Int?,
|
||||
@ColumnInfo val sourceType: NotaDescriptor.Source,
|
||||
@ColumnInfo val source: String,
|
||||
) {
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var uid: Int = 0
|
||||
|
||||
@ColumnInfo
|
||||
var uuid: UUID = UUID.nameUUIDFromBytes("${title}${artistId}".toByteArray())
|
||||
}
|
||||
|
||||
@Dao
|
||||
interface TrackDao {
|
||||
@Insert
|
||||
fun insertTrack(track: Track)
|
||||
|
||||
@Query("SELECT * FROM track")
|
||||
fun getAll(): List<Track>
|
||||
|
||||
@Query("SELECT * FROM track WHERE :artistId = artistId")
|
||||
fun getByArtistId(artistId: Int): List<Track>
|
||||
|
||||
@Query("SELECT * FROM track WHERE :albumId = albumId")
|
||||
fun getByAlbumId(albumId: Int): List<Track>
|
||||
}
|
Loading…
Reference in New Issue