/* * Copyright (c) 2020 Hemanth Savarla. * * Licensed under the GNU General Public License v3 * * This is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or (at your option) any later version. * * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for more details. * */ package code.name.monkey.retromusic.db import androidx.lifecycle.LiveData import androidx.room.* @Dao interface PlaylistDao { @Insert suspend fun createPlaylist(playlistEntity: PlaylistEntity): Long @Query("UPDATE PlaylistEntity SET playlist_name = :name WHERE playlist_id = :playlistId") suspend fun renamePlaylist(playlistId: Long, name: String) @Query("SELECT * FROM PlaylistEntity WHERE playlist_name = :name") fun isPlaylistExists(name: String): List @Query("SELECT * FROM PlaylistEntity") suspend fun playlists(): List @Query("DELETE FROM SongEntity WHERE playlist_creator_id = :playlistId") suspend fun deletePlaylistSongs(playlistId: Long) @Query("DELETE FROM SongEntity WHERE playlist_creator_id = :playlistId AND id = :songId") suspend fun deleteSongFromPlaylist(playlistId: Long, songId: Long) @Transaction @Query("SELECT * FROM PlaylistEntity") suspend fun playlistsWithSongs(): List @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertSongsToPlaylist(songEntities: List) @Query("SELECT * FROM SongEntity WHERE playlist_creator_id = :playlistId AND id = :songId") suspend fun isSongExistsInPlaylist(playlistId: Long, songId: Long): List @Query("SELECT * FROM SongEntity WHERE playlist_creator_id = :playlistId") fun songsFromPlaylist(playlistId: Long): LiveData> @Delete suspend fun deletePlaylist(playlistEntity: PlaylistEntity) @Delete suspend fun deletePlaylists(playlistEntities: List) @Delete suspend fun deletePlaylistSongs(songs: List) @Query("SELECT * FROM SongEntity WHERE playlist_creator_id= :playlistId") fun favoritesSongsLiveData(playlistId: Long): LiveData> @Query("SELECT * FROM SongEntity WHERE playlist_creator_id= :playlistId") fun favoritesSongs(playlistId: Long): List }