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

68 lines
2.5 KiB
Kotlin
Raw Normal View History

2020-10-06 08:46:04 +00:00
/*
* 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
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 renamePlaylist(playlistId: Long, name: String)
@Query("SELECT * FROM PlaylistEntity WHERE playlist_name = :name")
2020-08-23 08:01:42 +00:00
fun isPlaylistExists(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")
suspend fun deletePlaylistSongs(playlistId: Long)
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 deleteSongFromPlaylist(playlistId: Long, songId: Long)
2020-08-23 08:01:42 +00:00
@Transaction
@Query("SELECT * FROM PlaylistEntity")
2020-08-23 08:01:42 +00:00
suspend fun playlistsWithSongs(): List<PlaylistWithSongs>
@Insert(onConflict = OnConflictStrategy.REPLACE)
2020-08-23 08:01:42 +00:00
suspend fun insertSongsToPlaylist(songEntities: List<SongEntity>)
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id = :playlistId AND id = :songId")
suspend fun isSongExistsInPlaylist(playlistId: Long, songId: Long): 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")
fun songsFromPlaylist(playlistId: Long): LiveData<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-09-10 19:22:10 +00:00
suspend fun deletePlaylistSongs(songs: List<SongEntity>)
2020-08-21 13:05:01 +00:00
2020-08-21 14:47:25 +00:00
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id= :playlistId")
fun favoritesSongsLiveData(playlistId: Long): LiveData<List<SongEntity>>
2020-08-21 14:47:25 +00:00
@Query("SELECT * FROM SongEntity WHERE playlist_creator_id= :playlistId")
fun favoritesSongs(playlistId: Long): List<SongEntity>
2020-10-06 08:46:04 +00:00
}