2020-08-19 18:43:06 +00:00
|
|
|
package code.name.monkey.retromusic.db
|
|
|
|
|
2020-08-21 14:19:15 +00:00
|
|
|
import androidx.lifecycle.LiveData
|
2020-08-19 18:43:06 +00:00
|
|
|
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")
|
2020-08-23 08:01:42 +00:00
|
|
|
suspend fun renamePlaylist(playlistId: Int, name: String)
|
2020-08-20 06:49:08 +00:00
|
|
|
|
|
|
|
@Query("SELECT * FROM PlaylistEntity WHERE playlist_name = :name")
|
2020-08-23 08:01:42 +00:00
|
|
|
fun isPlaylistExists(name: String): List<PlaylistEntity>
|
2020-08-20 06:49:08 +00:00
|
|
|
|
2020-08-19 18:43:06 +00:00
|
|
|
@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
|
|
|
|
2020-08-23 08:01:42 +00:00
|
|
|
@Query("DELETE FROM SongEntity WHERE playlist_creator_id = :playlistId AND id = :songId")
|
|
|
|
suspend fun removeSongFromPlaylist(playlistId: Int, songId: Int)
|
|
|
|
|
2020-08-19 18:43:06 +00:00
|
|
|
@Transaction
|
|
|
|
@Query("SELECT * FROM PlaylistEntity")
|
2020-08-23 08:01:42 +00:00
|
|
|
suspend fun playlistsWithSongs(): List<PlaylistWithSongs>
|
2020-08-19 18:43:06 +00:00
|
|
|
|
|
|
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
2020-08-23 08:01:42 +00:00
|
|
|
suspend fun insertSongsToPlaylist(songEntities: List<SongEntity>)
|
2020-08-20 06:49:08 +00:00
|
|
|
|
2020-08-21 11:43:51 +00:00
|
|
|
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id = :playlistId AND id = :songId")
|
2020-08-23 08:01:42 +00:00
|
|
|
suspend fun isSongExistsInPlaylist(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-23 08:01:42 +00:00
|
|
|
suspend fun songsFromPlaylist(playlistId: Int): List<SongEntity>
|
2020-08-21 12:12:40 +00:00
|
|
|
|
2020-08-20 10:06:59 +00:00
|
|
|
@Delete
|
2020-08-23 08:01:42 +00:00
|
|
|
suspend fun deletePlaylist(playlistEntity: PlaylistEntity)
|
2020-08-20 20:02:40 +00:00
|
|
|
|
|
|
|
@Delete
|
2020-08-23 08:01:42 +00:00
|
|
|
suspend fun deletePlaylists(playlistEntities: List<PlaylistEntity>)
|
2020-08-20 20:02:40 +00:00
|
|
|
|
|
|
|
@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
|
|
|
|
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
|
|
|
|
2020-08-23 08:01:42 +00:00
|
|
|
|
2020-08-19 18:43:06 +00:00
|
|
|
}
|