mirror of
https://github.com/YGGverse/rssto.git
synced 2026-03-31 17:15:29 +00:00
use FromRow trait
This commit is contained in:
parent
5e0735ebe1
commit
4c99208535
1 changed files with 22 additions and 58 deletions
|
|
@ -40,9 +40,7 @@ impl Mysql {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn channel_item(&self, channel_item_id: u64) -> Result<Option<ChannelItem>, Error> {
|
pub fn channel_item(&self, channel_item_id: u64) -> Result<Option<ChannelItem>, Error> {
|
||||||
self.pool
|
self.pool.get_conn()?.exec_first(
|
||||||
.get_conn()?
|
|
||||||
.exec_first(
|
|
||||||
"SELECT `channel_item_id`,
|
"SELECT `channel_item_id`,
|
||||||
`channel_id`,
|
`channel_id`,
|
||||||
`pub_date`,
|
`pub_date`,
|
||||||
|
|
@ -52,21 +50,6 @@ impl Mysql {
|
||||||
`description` FROM `channel_item` WHERE `channel_item_id` = ?",
|
`description` FROM `channel_item` WHERE `channel_item_id` = ?",
|
||||||
(channel_item_id,),
|
(channel_item_id,),
|
||||||
)
|
)
|
||||||
.map(|row| {
|
|
||||||
row.map(
|
|
||||||
|(channel_item_id, channel_id, pub_date, guid, link, title, description)| {
|
|
||||||
ChannelItem {
|
|
||||||
channel_item_id,
|
|
||||||
channel_id,
|
|
||||||
pub_date,
|
|
||||||
guid,
|
|
||||||
link,
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
}
|
|
||||||
},
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn channel_items_by_channel_id_guid(
|
pub fn channel_items_by_channel_id_guid(
|
||||||
|
|
@ -75,7 +58,7 @@ impl Mysql {
|
||||||
guid: &str,
|
guid: &str,
|
||||||
limit: Option<usize>,
|
limit: Option<usize>,
|
||||||
) -> Result<Vec<ChannelItem>, Error> {
|
) -> Result<Vec<ChannelItem>, Error> {
|
||||||
self.pool.get_conn()?.exec_map(
|
self.pool.get_conn()?.exec(
|
||||||
format!(
|
format!(
|
||||||
"SELECT `channel_item_id`,
|
"SELECT `channel_item_id`,
|
||||||
`channel_id`,
|
`channel_id`,
|
||||||
|
|
@ -87,15 +70,6 @@ impl Mysql {
|
||||||
limit.unwrap_or(DEFAULT_LIMIT)
|
limit.unwrap_or(DEFAULT_LIMIT)
|
||||||
),
|
),
|
||||||
(channel_id, guid),
|
(channel_id, guid),
|
||||||
|(channel_item_id, channel_id, pub_date, guid, link, title, description)| ChannelItem {
|
|
||||||
channel_item_id,
|
|
||||||
channel_id,
|
|
||||||
pub_date,
|
|
||||||
guid,
|
|
||||||
link,
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -141,23 +115,14 @@ impl Mysql {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn contents(&self, limit: Option<usize>) -> Result<Vec<Content>, Error> {
|
pub fn contents(&self, limit: Option<usize>) -> Result<Vec<Content>, Error> {
|
||||||
self.pool.get_conn()?.query_map(
|
self.pool.get_conn()?.query(format!(
|
||||||
format!(
|
|
||||||
"SELECT `content_id`,
|
"SELECT `content_id`,
|
||||||
`channel_item_id`,
|
`channel_item_id`,
|
||||||
`source_id`,
|
`source_id`,
|
||||||
`title`,
|
`title`,
|
||||||
`description` FROM `content` LIMIT {}",
|
`description` FROM `content` LIMIT {}",
|
||||||
limit.unwrap_or(DEFAULT_LIMIT)
|
limit.unwrap_or(DEFAULT_LIMIT)
|
||||||
),
|
))
|
||||||
|(content_id, channel_item_id, source_id, title, description)| Content {
|
|
||||||
content_id,
|
|
||||||
channel_item_id,
|
|
||||||
source_id,
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn contents_by_channel_item_id_source_id(
|
pub fn contents_by_channel_item_id_source_id(
|
||||||
|
|
@ -166,7 +131,7 @@ impl Mysql {
|
||||||
source_id: Option<u64>,
|
source_id: Option<u64>,
|
||||||
limit: Option<usize>,
|
limit: Option<usize>,
|
||||||
) -> Result<Vec<Content>, Error> {
|
) -> Result<Vec<Content>, Error> {
|
||||||
self.pool.get_conn()?.exec_map(
|
self.pool.get_conn()?.exec(
|
||||||
format!(
|
format!(
|
||||||
"SELECT `content_id`,
|
"SELECT `content_id`,
|
||||||
`channel_item_id`,
|
`channel_item_id`,
|
||||||
|
|
@ -176,7 +141,6 @@ impl Mysql {
|
||||||
limit.unwrap_or(DEFAULT_LIMIT)
|
limit.unwrap_or(DEFAULT_LIMIT)
|
||||||
),
|
),
|
||||||
(channel_item_id, source_id),
|
(channel_item_id, source_id),
|
||||||
|(content_id, channel_item_id,source_id, title, description)| Content { content_id, channel_item_id, source_id, title, description },
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -196,13 +160,13 @@ impl Mysql {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq, FromRow)]
|
||||||
pub struct Channel {
|
pub struct Channel {
|
||||||
pub channel_id: u64,
|
pub channel_id: u64,
|
||||||
pub url: String,
|
pub url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq, FromRow)]
|
||||||
pub struct ChannelItem {
|
pub struct ChannelItem {
|
||||||
pub channel_item_id: u64,
|
pub channel_item_id: u64,
|
||||||
pub channel_id: u64,
|
pub channel_id: u64,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue