PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/db/PlaylistDao.kt

80 lines
2.9 KiB
Kotlin
Raw Normal View History

package code.name.monkey.retromusic.db
2020-08-21 14:19:15 +00:00
import androidx.lifecycle.LiveData
import androidx.room.*
@Dao
interface PlaylistDao {
2020-08-20 20:02:40 +00:00
@Insert
suspend fun createPlaylist(playlistEntity: PlaylistEntity): Long
@Query("UPDATE PlaylistEntity SET playlist_name = :name WHERE playlist_id = :playlistId")
suspend fun renamePlaylistEntity(playlistId: Int, name: String)
@Query("SELECT * FROM PlaylistEntity WHERE playlist_name = :name")
2020-08-21 14:47:25 +00:00
fun checkPlaylistExists(name: String): List<PlaylistEntity>
@Query("SELECT * FROM PlaylistEntity")
suspend fun playlists(): List<PlaylistEntity>
2020-08-20 20:02:40 +00:00
@Query("DELETE FROM SongEntity WHERE playlist_creator_id = :playlistId")
2020-08-21 17:07:10 +00:00
suspend fun deleteSongsInPlaylist(playlistId: Int)
2020-08-20 20:02:40 +00:00
@Transaction
@Query("SELECT * FROM PlaylistEntity")
suspend fun playlistsWithSong(): List<PlaylistWithSongs>
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertSongs(songEntities: List<SongEntity>)
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id = :playlistId AND id = :songId")
suspend fun checkSongExistsWithPlaylistId(playlistId: Int, songId: Int): List<SongEntity>
2020-08-20 09:52:38 +00:00
2020-08-20 20:02:40 +00:00
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id = :playlistId")
2020-08-20 09:52:38 +00:00
suspend fun getSongs(playlistId: Int): List<SongEntity>
2020-08-20 10:06:59 +00:00
2020-08-21 12:12:40 +00:00
@Query("DELETE FROM SongEntity WHERE playlist_creator_id = :playlistId AND id = :songId")
fun removeSong(playlistId: Int, songId: Int)
2020-08-20 10:06:59 +00:00
@Delete
2020-08-20 20:02:40 +00:00
suspend fun deletePlaylistEntity(playlistEntity: PlaylistEntity)
@Delete
suspend fun deletePlaylistEntities(playlistEntities: List<PlaylistEntity>)
@Delete
2020-08-21 17:07:10 +00:00
suspend fun deleteSongsInPlaylist(songs: List<SongEntity>)
2020-08-21 13:05:01 +00:00
2020-08-21 14:19:15 +00:00
@Insert(onConflict = OnConflictStrategy.REPLACE)
2020-08-21 17:07:10 +00:00
suspend fun insertSongInHistory(historyEntity: HistoryEntity)
2020-08-21 14:19:15 +00:00
@Query("SELECT * FROM HistoryEntity WHERE id = :songId LIMIT 1")
2020-08-21 17:07:10 +00:00
suspend fun isSongPresentInHistory(songId: Int): HistoryEntity?
2020-08-21 14:19:15 +00:00
@Update
suspend fun updateHistorySong(historyEntity: HistoryEntity)
@Query("SELECT * FROM HistoryEntity ORDER BY time_played DESC")
fun historySongs(): LiveData<List<HistoryEntity>>
2020-08-21 14:47:25 +00:00
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id= :playlistId")
fun favoritesSongsLiveData(playlistId: Int): LiveData<List<SongEntity>>
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id= :playlistId")
fun favoritesSongs(playlistId: Int): List<SongEntity>
2020-08-21 17:07:10 +00:00
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertSongInPlayCount(playCountEntity: PlayCountEntity)
@Update
fun updateSongInPlayCount(playCountEntity: PlayCountEntity)
@Delete
fun deleteSongInPlayCount(playCountEntity: PlayCountEntity)
@Query("SELECT * FROM PlayCountEntity WHERE id =:songId")
fun checkSongExistInPlayCount(songId: Int): List<PlayCountEntity>
@Query("SELECT * FROM PlayCountEntity ORDER BY play_count DESC")
fun playCountSongs(): List<PlayCountEntity>
}