mirror of https://github.com/readrops/Readrops.git
Migrate some DAOs to interface
This commit is contained in:
parent
f1d49e43dc
commit
19c5b8b17e
|
@ -13,65 +13,65 @@ import com.readrops.db.pojo.FeedWithFolder
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
abstract class FeedDao : BaseDao<Feed> {
|
interface FeedDao : BaseDao<Feed> {
|
||||||
|
|
||||||
@Query("Select * From Feed Where id = :feedId")
|
@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")
|
@Query("Select * From Feed Where folder_id = :folderId")
|
||||||
abstract suspend fun selectFeedsByFolder(folderId: Int): List<Feed>
|
suspend fun selectFeedsByFolder(folderId: Int): List<Feed>
|
||||||
|
|
||||||
@Query("Select * from Feed Where account_id = :accountId order by name ASC")
|
@Query("Select * from Feed Where account_id = :accountId order by name ASC")
|
||||||
abstract suspend fun selectFeeds(accountId: Int): List<Feed>
|
suspend fun selectFeeds(accountId: Int): List<Feed>
|
||||||
|
|
||||||
@Query("Update Feed set etag = :etag, last_modified = :lastModified Where id = :feedId")
|
@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")
|
@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])
|
@RawQuery(observedEntities = [Feed::class, Item::class])
|
||||||
abstract fun selectFeedsWithoutFolder(query: SupportSQLiteQuery): Flow<List<FeedWithCount>>
|
fun selectFeedsWithoutFolder(query: SupportSQLiteQuery): Flow<List<FeedWithCount>>
|
||||||
|
|
||||||
@Query("Update Feed set name = :feedName, url = :feedUrl, folder_id = :folderId Where id = :feedId")
|
@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")
|
@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")
|
@Query("Select remote_id From Feed Where account_id = :accountId")
|
||||||
abstract suspend fun selectFeedRemoteIds(accountId: Int): MutableList<String>
|
suspend fun selectFeedRemoteIds(accountId: Int): MutableList<String>
|
||||||
|
|
||||||
@Query("Select id From Folder Where remoteId = :remoteId And account_id = :accountId")
|
@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")
|
@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")
|
@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")
|
@Query("Delete from Feed Where remote_id in (:ids) And account_id = :accountId")
|
||||||
abstract fun deleteByIds(ids: List<String>, accountId: Int)
|
fun deleteByIds(ids: List<String>, accountId: Int)
|
||||||
|
|
||||||
@Query("Update Feed set color = :color Where id = :feedId")
|
@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
|
@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""")
|
Where Feed.account_id = :accountId Order By Feed.name, Folder.name""")
|
||||||
abstract fun selectFeedsWithFolderName(accountId: Int): Flow<List<FeedWithFolder>>
|
fun selectFeedsWithFolderName(accountId: Int): Flow<List<FeedWithFolder>>
|
||||||
|
|
||||||
@Query("Update Feed set notification_enabled = :enabled Where id = :feedId")
|
@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")
|
@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)")
|
@Query("Select * From Feed Where id in (:ids)")
|
||||||
abstract suspend fun selectFromIds(ids: List<Int>): List<Feed>
|
suspend fun selectFromIds(ids: List<Int>): List<Feed>
|
||||||
|
|
||||||
@Query("Update Feed set icon_url = :iconUrl Where id = :feedId")
|
@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
|
* Insert, update and delete feeds by account
|
||||||
|
@ -81,7 +81,7 @@ abstract class FeedDao : BaseDao<Feed> {
|
||||||
* @return newly inserted feeds
|
* @return newly inserted feeds
|
||||||
*/
|
*/
|
||||||
@Transaction
|
@Transaction
|
||||||
open suspend fun upsertFeeds(feeds: List<Feed>, account: Account): List<Feed> {
|
suspend fun upsertFeeds(feeds: List<Feed>, account: Account): List<Feed> {
|
||||||
val localFeedIds = selectFeedRemoteIds(account.id)
|
val localFeedIds = selectFeedRemoteIds(account.id)
|
||||||
|
|
||||||
val feedsToInsert = feeds.filter { feed -> localFeedIds.none { localFeedId -> feed.remoteId == localFeedId } }
|
val feedsToInsert = feeds.filter { feed -> localFeedIds.none { localFeedId -> feed.remoteId == localFeedId } }
|
||||||
|
|
|
@ -14,59 +14,59 @@ import com.readrops.db.pojo.ItemWithFeed
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@Dao
|
@Dao
|
||||||
abstract class ItemDao : BaseDao<Item> {
|
interface ItemDao : BaseDao<Item> {
|
||||||
|
|
||||||
@Query("Select * From Item Where id = :itemId")
|
@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])
|
@RawQuery(observedEntities = [Item::class, Feed::class, Folder::class, ItemState::class])
|
||||||
abstract fun selectAll(query: SupportSQLiteQuery): PagingSource<Int, ItemWithFeed>
|
fun selectAll(query: SupportSQLiteQuery): PagingSource<Int, ItemWithFeed>
|
||||||
|
|
||||||
@RawQuery(observedEntities = [Item::class, ItemState::class])
|
@RawQuery(observedEntities = [Item::class, ItemState::class])
|
||||||
abstract fun selectItemById(query: SupportSQLiteQuery): Flow<ItemWithFeed>
|
fun selectItemById(query: SupportSQLiteQuery): Flow<ItemWithFeed>
|
||||||
|
|
||||||
@Query("Update Item Set read = :read Where id = :itemId")
|
@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")
|
@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")
|
@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)")
|
@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)")
|
@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') " +
|
@Query("Update Item set read = 1 Where DateTime(Round(pub_date / 1000), 'unixepoch') " +
|
||||||
"Between DateTime(DateTime(\"now\"), \"-24 hour\") And DateTime(\"now\") " +
|
"Between DateTime(DateTime(\"now\"), \"-24 hour\") And DateTime(\"now\") " +
|
||||||
"And feed_id IN (Select id From Feed Where account_id = :accountId)")
|
"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 " +
|
@Query("Update Item set read = 1 Where feed_id IN " +
|
||||||
"(Select id From Feed Where id = :feedId And account_id = :accountId)")
|
"(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 " +
|
@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)")
|
"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
|
@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')
|
And account_id = :accountId And DateTime(Round(Item.pub_date / 1000), 'unixepoch')
|
||||||
Between DateTime(DateTime("now"), "-24 hour") And DateTime("now")""")
|
Between DateTime(DateTime("now"), "-24 hour") And DateTime("now")""")
|
||||||
abstract fun selectUnreadNewItemsCount(accountId: Int): Flow<Int>
|
fun selectUnreadNewItemsCount(accountId: Int): Flow<Int>
|
||||||
|
|
||||||
@Query("""Select count(*) From ItemState Inner Join Item On Item.remote_id = ItemState.remote_id
|
@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')
|
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")""")
|
Between DateTime(DateTime("now"), "-24 hour") And DateTime("now")""")
|
||||||
abstract fun selectUnreadNewItemsCountByItemState(accountId: Int): Flow<Int>
|
fun selectUnreadNewItemsCountByItemState(accountId: Int): Flow<Int>
|
||||||
|
|
||||||
@RawQuery(observedEntities = [Item::class, ItemState::class])
|
@RawQuery(observedEntities = [Item::class, ItemState::class])
|
||||||
abstract fun selectFeedUnreadItemsCount(query: SupportSQLiteQuery):
|
fun selectFeedUnreadItemsCount(query: SupportSQLiteQuery):
|
||||||
Flow<Map<@MapColumn(columnName = "feed_id") Int, @MapColumn(columnName = "item_count") Int>>
|
Flow<Map<@MapColumn(columnName = "feed_id") Int, @MapColumn(columnName = "item_count") Int>>
|
||||||
|
|
||||||
@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")
|
@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
|
||||||
}
|
}
|
Loading…
Reference in New Issue