mirror of
https://github.com/YGGverse/rssto.git
synced 2026-04-01 17:45:30 +00:00
implement initial llm features
This commit is contained in:
parent
5608e2e081
commit
de3fda435a
10 changed files with 269 additions and 14 deletions
|
|
@ -108,7 +108,7 @@ impl Mysql {
|
|||
|
||||
pub fn contents_total_by_provider_id(&self, provider_id: Option<u64>) -> Result<usize, Error> {
|
||||
let total: Option<usize> = self.pool.get_conn()?.exec_first(
|
||||
"SELECT COUNT(*) FROM `content` WHERE `provider_id` = ?",
|
||||
"SELECT COUNT(*) FROM `content` WHERE `provider_id` <=> ?",
|
||||
(provider_id,),
|
||||
)?;
|
||||
Ok(total.unwrap_or(0))
|
||||
|
|
@ -125,12 +125,35 @@ impl Mysql {
|
|||
`channel_item_id`,
|
||||
`provider_id`,
|
||||
`title`,
|
||||
`description` FROM `content` WHERE `provider_id` = ? ORDER BY `content_id` {sort} LIMIT {}",
|
||||
`description` FROM `content` WHERE `provider_id` <=> ? ORDER BY `content_id` {sort} LIMIT {}",
|
||||
limit.unwrap_or(DEFAULT_LIMIT)
|
||||
),
|
||||
(provider_id, ))
|
||||
}
|
||||
|
||||
/// Get subjects for `rssto-llm` queue
|
||||
pub fn contents_queue_for_provider_id(
|
||||
&self,
|
||||
provider_id: u64,
|
||||
sort: Sort,
|
||||
limit: Option<usize>,
|
||||
) -> Result<Vec<Content>, Error> {
|
||||
self.pool.get_conn()?.exec(
|
||||
format!(
|
||||
"SELECT `c1`.`content_id`,
|
||||
`c1`.`channel_item_id`,
|
||||
`c1`.`provider_id`,
|
||||
`c1`.`title`,
|
||||
`c1`.`description`
|
||||
FROM `content` AS `c1` WHERE `c1`.`provider_id` IS NULL AND NOT EXISTS (
|
||||
SELECT NULL FROM `content` AS `c2` WHERE `c2`.`channel_item_id` = `c1`.`channel_item_id` AND `c2`.`provider_id` = ? LIMIT 1
|
||||
) ORDER BY `c1`.`content_id` {sort} LIMIT {}",
|
||||
limit.unwrap_or(DEFAULT_LIMIT)
|
||||
),
|
||||
(provider_id,),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn contents_by_channel_item_id_provider_id(
|
||||
&self,
|
||||
channel_item_id: u64,
|
||||
|
|
@ -143,7 +166,7 @@ impl Mysql {
|
|||
`channel_item_id`,
|
||||
`provider_id`,
|
||||
`title`,
|
||||
`description` FROM `content` WHERE `channel_item_id` = ? AND `provider_id` = ? LIMIT {}",
|
||||
`description` FROM `content` WHERE `channel_item_id` = ? AND `provider_id` <=> ? LIMIT {}",
|
||||
limit.unwrap_or(DEFAULT_LIMIT)
|
||||
),
|
||||
(channel_item_id, provider_id),
|
||||
|
|
@ -154,8 +177,8 @@ impl Mysql {
|
|||
&self,
|
||||
channel_item_id: u64,
|
||||
provider_id: Option<u64>,
|
||||
title: String,
|
||||
description: String,
|
||||
title: &str,
|
||||
description: &str,
|
||||
) -> Result<u64, Error> {
|
||||
let mut c = self.pool.get_conn()?;
|
||||
c.exec_drop(
|
||||
|
|
@ -164,6 +187,21 @@ impl Mysql {
|
|||
)?;
|
||||
Ok(c.last_insert_id())
|
||||
}
|
||||
|
||||
pub fn provider_by_name(&self, name: &str) -> Result<Option<Provider>, Error> {
|
||||
self.pool.get_conn()?.exec_first(
|
||||
"SELECT `provider_id`,
|
||||
`name`
|
||||
FROM `provider` WHERE `name` = ?",
|
||||
(name,),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn insert_provider(&self, name: &str) -> Result<u64, Error> {
|
||||
let mut c = self.pool.get_conn()?;
|
||||
c.exec_drop("INSERT INTO `provider` SET `name` = ?", (name,))?;
|
||||
Ok(c.last_insert_id())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, FromRow)]
|
||||
|
|
@ -194,6 +232,12 @@ pub struct Content {
|
|||
pub description: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, FromRow)]
|
||||
pub struct Provider {
|
||||
pub provider_id: u64,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
pub enum Sort {
|
||||
Asc,
|
||||
Desc,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue