diff --git a/db/src/main/java/com/readrops/db/dao/FeedDao.kt b/db/src/main/java/com/readrops/db/dao/FeedDao.kt index 3542e925..5aa8aac8 100644 --- a/db/src/main/java/com/readrops/db/dao/FeedDao.kt +++ b/db/src/main/java/com/readrops/db/dao/FeedDao.kt @@ -13,65 +13,65 @@ import com.readrops.db.pojo.FeedWithFolder import kotlinx.coroutines.flow.Flow @Dao -abstract class FeedDao : BaseDao { +interface FeedDao : BaseDao { @Query("Select * From Feed Where id = :feedId") - abstract suspend fun selectFeed(feedId: Int): Feed + suspend fun selectFeed(feedId: Int): Feed @Query("Select * From Feed Where folder_id = :folderId") - abstract suspend fun selectFeedsByFolder(folderId: Int): List + suspend fun selectFeedsByFolder(folderId: Int): List @Query("Select * from Feed Where account_id = :accountId order by name ASC") - abstract suspend fun selectFeeds(accountId: Int): List + suspend fun selectFeeds(accountId: Int): List @Query("Update Feed set etag = :etag, last_modified = :lastModified Where id = :feedId") - abstract suspend fun updateHeaders(etag: String, lastModified: String, feedId: Int) + suspend fun updateHeaders(etag: String, lastModified: String, feedId: Int) @Query("Select case When :feedUrl In (Select url from Feed Where account_id = :accountId) Then 1 else 0 end") - abstract suspend fun feedExists(feedUrl: String, accountId: Int): Boolean + suspend fun feedExists(feedUrl: String, accountId: Int): Boolean @RawQuery(observedEntities = [Feed::class, Item::class]) - abstract fun selectFeedsWithoutFolder(query: SupportSQLiteQuery): Flow> + fun selectFeedsWithoutFolder(query: SupportSQLiteQuery): Flow> @Query("Update Feed set name = :feedName, url = :feedUrl, folder_id = :folderId Where id = :feedId") - abstract fun updateFeedFields(feedId: Int, feedName: String, feedUrl: String, folderId: Int?) + fun updateFeedFields(feedId: Int, feedName: String, feedUrl: String, folderId: Int?) @Query("Select count(*) from Feed Where account_id = :accountId") - abstract suspend fun selectFeedCount(accountId: Int): Int + suspend fun selectFeedCount(accountId: Int): Int @Query("Select remote_id From Feed Where account_id = :accountId") - abstract suspend fun selectFeedRemoteIds(accountId: Int): MutableList + suspend fun selectFeedRemoteIds(accountId: Int): MutableList @Query("Select id From Folder Where remoteId = :remoteId And account_id = :accountId") - abstract suspend fun selectRemoteFolderLocalId(remoteId: String, accountId: Int): Int + suspend fun selectRemoteFolderLocalId(remoteId: String, accountId: Int): Int @Query("Select id From Feed Where remote_id = :remoteId And account_id = :accountId") - abstract suspend fun selectRemoteFeedLocalId(remoteId: String, accountId: Int): Int + suspend fun selectRemoteFeedLocalId(remoteId: String, accountId: Int): Int @Query("Update Feed set name = :name, folder_id = :folderId Where remote_id = :remoteFeedId And account_id = :accountId") - abstract fun updateFeedNameAndFolder(remoteFeedId: String, accountId: Int, name: String, folderId: Int?) + fun updateFeedNameAndFolder(remoteFeedId: String, accountId: Int, name: String, folderId: Int?) @Query("Delete from Feed Where remote_id in (:ids) And account_id = :accountId") - abstract fun deleteByIds(ids: List, accountId: Int) + fun deleteByIds(ids: List, accountId: Int) @Query("Update Feed set color = :color Where id = :feedId") - abstract fun updateFeedColor(feedId: Int, color: Int) + fun updateFeedColor(feedId: Int, color: Int) @Query("""Select Feed.*, Folder.name as folder_name From Feed Left Join Folder On Feed.folder_id = Folder.id Where Feed.account_id = :accountId Order By Feed.name, Folder.name""") - abstract fun selectFeedsWithFolderName(accountId: Int): Flow> + fun selectFeedsWithFolderName(accountId: Int): Flow> @Query("Update Feed set notification_enabled = :enabled Where id = :feedId") - abstract suspend fun updateFeedNotificationState(feedId: Int, enabled: Boolean) + suspend fun updateFeedNotificationState(feedId: Int, enabled: Boolean) @Query("Update Feed set notification_enabled = :enabled Where account_id = :accountId") - abstract suspend fun updateAllFeedsNotificationState(accountId: Int, enabled: Boolean) + suspend fun updateAllFeedsNotificationState(accountId: Int, enabled: Boolean) @Query("Select * From Feed Where id in (:ids)") - abstract suspend fun selectFromIds(ids: List): List + suspend fun selectFromIds(ids: List): List @Query("Update Feed set icon_url = :iconUrl Where id = :feedId") - abstract suspend fun updateFeedIconUrl(feedId: Int, iconUrl: String) + suspend fun updateFeedIconUrl(feedId: Int, iconUrl: String) /** * Insert, update and delete feeds by account @@ -81,7 +81,7 @@ abstract class FeedDao : BaseDao { * @return newly inserted feeds */ @Transaction - open suspend fun upsertFeeds(feeds: List, account: Account): List { + suspend fun upsertFeeds(feeds: List, account: Account): List { val localFeedIds = selectFeedRemoteIds(account.id) val feedsToInsert = feeds.filter { feed -> localFeedIds.none { localFeedId -> feed.remoteId == localFeedId } } diff --git a/db/src/main/java/com/readrops/db/dao/ItemDao.kt b/db/src/main/java/com/readrops/db/dao/ItemDao.kt index e86a982f..f5a391ce 100644 --- a/db/src/main/java/com/readrops/db/dao/ItemDao.kt +++ b/db/src/main/java/com/readrops/db/dao/ItemDao.kt @@ -14,59 +14,59 @@ import com.readrops.db.pojo.ItemWithFeed import kotlinx.coroutines.flow.Flow @Dao -abstract class ItemDao : BaseDao { +interface ItemDao : BaseDao { @Query("Select * From Item Where id = :itemId") - abstract fun select(itemId: Int): Item + fun select(itemId: Int): Item @RawQuery(observedEntities = [Item::class, Feed::class, Folder::class, ItemState::class]) - abstract fun selectAll(query: SupportSQLiteQuery): PagingSource + fun selectAll(query: SupportSQLiteQuery): PagingSource @RawQuery(observedEntities = [Item::class, ItemState::class]) - abstract fun selectItemById(query: SupportSQLiteQuery): Flow + fun selectItemById(query: SupportSQLiteQuery): Flow @Query("Update Item Set read = :read Where id = :itemId") - abstract suspend fun updateReadState(itemId: Int, read: Boolean) + suspend fun updateReadState(itemId: Int, read: Boolean) @Query("Update Item Set starred = :starred Where id = :itemId") - abstract suspend fun updateStarState(itemId: Int, starred: Boolean) + suspend fun updateStarState(itemId: Int, starred: Boolean) @Query("Update Item set read = :read, starred = :starred Where remote_id = :remoteId") - abstract suspend fun updateReadAndStarState(remoteId: String, read: Boolean, starred: Boolean) + suspend fun updateReadAndStarState(remoteId: String, read: Boolean, starred: Boolean) @Query("Update Item set read = 1 Where feed_id IN (Select id From Feed Where account_id = :accountId)") - abstract suspend fun setAllItemsRead(accountId: Int) + suspend fun setAllItemsRead(accountId: Int) @Query("Update Item set read = 1 Where starred = 1 And feed_id IN (Select id From Feed Where account_id = :accountId)") - abstract suspend fun setAllStarredItemsRead(accountId: Int) + suspend fun setAllStarredItemsRead(accountId: Int) @Query("Update Item set read = 1 Where DateTime(Round(pub_date / 1000), 'unixepoch') " + "Between DateTime(DateTime(\"now\"), \"-24 hour\") And DateTime(\"now\") " + "And feed_id IN (Select id From Feed Where account_id = :accountId)") - abstract suspend fun setAllNewItemsRead(accountId: Int) + suspend fun setAllNewItemsRead(accountId: Int) @Query("Update Item set read = 1 Where feed_id IN " + "(Select id From Feed Where id = :feedId And account_id = :accountId)") - abstract suspend fun setAllItemsReadByFeed(feedId: Int, accountId: Int) + suspend fun setAllItemsReadByFeed(feedId: Int, accountId: Int) @Query("Update Item set read = 1 Where feed_id IN (Select Feed.id From Feed Inner Join Folder " + "On Feed.folder_id = Folder.id Where Folder.id = :folderId And Folder.account_id = :accountId)") - abstract suspend fun setAllItemsReadByFolder(folderId: Int, accountId: Int) + suspend fun setAllItemsReadByFolder(folderId: Int, accountId: Int) @Query("""Select count(*) From Item Inner Join Feed On Item.feed_id = Feed.id Where read = 0 And account_id = :accountId And DateTime(Round(Item.pub_date / 1000), 'unixepoch') Between DateTime(DateTime("now"), "-24 hour") And DateTime("now")""") - abstract fun selectUnreadNewItemsCount(accountId: Int): Flow + fun selectUnreadNewItemsCount(accountId: Int): Flow @Query("""Select count(*) From ItemState Inner Join Item On Item.remote_id = ItemState.remote_id Where ItemState.read = 0 and account_id = :accountId And DateTime(Round(Item.pub_date / 1000), 'unixepoch') Between DateTime(DateTime("now"), "-24 hour") And DateTime("now")""") - abstract fun selectUnreadNewItemsCountByItemState(accountId: Int): Flow + fun selectUnreadNewItemsCountByItemState(accountId: Int): Flow @RawQuery(observedEntities = [Item::class, ItemState::class]) - abstract fun selectFeedUnreadItemsCount(query: SupportSQLiteQuery): + fun selectFeedUnreadItemsCount(query: SupportSQLiteQuery): Flow> @Query("Select case When :remoteId In (Select Item.remote_id From Item Inner Join Feed on Item.feed_id = Feed.id and account_id = :accountId) Then 1 else 0 end") - abstract suspend fun itemExists(remoteId: String, accountId: Int): Boolean + suspend fun itemExists(remoteId: String, accountId: Int): Boolean } \ No newline at end of file