2020-08-19 18:43:06 +00:00
|
|
|
package code.name.monkey.retromusic.db
|
|
|
|
|
|
|
|
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)
|
2020-08-20 06:49:08 +00:00
|
|
|
|
|
|
|
@Query("SELECT * FROM PlaylistEntity WHERE playlist_name = :name")
|
|
|
|
suspend fun checkPlaylistExists(name: String): List<PlaylistEntity>
|
|
|
|
|
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")
|
|
|
|
suspend fun deleteSongsFromPlaylist(playlistId: Int)
|
|
|
|
|
2020-08-19 18:43:06 +00:00
|
|
|
@Transaction
|
|
|
|
@Query("SELECT * FROM PlaylistEntity")
|
|
|
|
suspend fun playlistsWithSong(): List<PlaylistWithSongs>
|
|
|
|
|
|
|
|
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
|
|
suspend fun insertSongs(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")
|
|
|
|
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
|
|
|
|
suspend fun removeSongsFromPlaylist(songs: List<SongEntity>)
|
2020-08-21 12:12:40 +00:00
|
|
|
|
2020-08-19 18:43:06 +00:00
|
|
|
}
|