db, add item and functions to get items
Creates item. It's pretty barebowns until I implement fetching. I also added get functions for feed and channel to get items with.
This commit is contained in:
parent
ac6e71eb62
commit
1c3f4cc854
5 changed files with 179 additions and 2 deletions
|
|
@ -5,8 +5,10 @@ use crate::{
|
|||
Channel,
|
||||
ChannelKey,
|
||||
FeedKey,
|
||||
Item,
|
||||
UserKey,
|
||||
channel::UnparsedChannel,
|
||||
item::UnparsedItem,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
@ -77,6 +79,22 @@ impl Feed {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_items(
|
||||
&self, pool: &AdapterPool, limit: u8, offset: u32
|
||||
) -> Result<Vec<Item>> {
|
||||
sqlx::query_as!(
|
||||
UnparsedItem,
|
||||
"SELECT i.id as `id!`, i.channel_id, i.fetched_at, i.title, i.description,
|
||||
i.content
|
||||
FROM items i
|
||||
JOIN feed_items fi on i.id = fi.item_id
|
||||
WHERE feed_id = ? AND archived = FALSE
|
||||
ORDER BY score DESC
|
||||
LIMIT ? OFFSET ?",
|
||||
self.key.0, limit, offset
|
||||
).fetch_all(&pool.0).await?.into_iter().map(UnparsedItem::parse).collect()
|
||||
}
|
||||
|
||||
pub async fn get_channels(
|
||||
&self, pool: &AdapterPool
|
||||
) -> Result<Vec<Channel>> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue