package org.schabi.newpipe.database.playlist.dao; import androidx.room.Dao; import androidx.room.Query; import androidx.room.Transaction; import org.schabi.newpipe.database.BasicDAO; import org.schabi.newpipe.database.playlist.model.PlaylistEntity; import java.util.List; import io.reactivex.rxjava3.core.Flowable; import static org.schabi.newpipe.database.playlist.model.PlaylistEntity.PLAYLIST_ID; import static org.schabi.newpipe.database.playlist.model.PlaylistEntity.PLAYLIST_TABLE; @Dao public interface PlaylistDAO extends BasicDAO { @Override @Query("SELECT * FROM " + PLAYLIST_TABLE) Flowable> getAll(); @Override @Query("DELETE FROM " + PLAYLIST_TABLE) int deleteAll(); @Override default Flowable> listByService(final int serviceId) { throw new UnsupportedOperationException(); } @Query("SELECT * FROM " + PLAYLIST_TABLE + " WHERE " + PLAYLIST_ID + " = :playlistId") Flowable> getPlaylist(long playlistId); @Query("DELETE FROM " + PLAYLIST_TABLE + " WHERE " + PLAYLIST_ID + " = :playlistId") int deletePlaylist(long playlistId); @Query("SELECT COUNT(*) FROM " + PLAYLIST_TABLE) Flowable getCount(); @Transaction default long upsertPlaylist(final PlaylistEntity playlist) { final long playlistId = playlist.getUid(); if (playlistId == -1) { // This situation is probably impossible. return insert(playlist); } else { update(playlist); return playlistId; } } }