format long rows

This commit is contained in:
yggverse 2026-01-07 21:59:11 +02:00
parent 6d3aac409a
commit 98ec671758

View file

@ -43,11 +43,20 @@ impl Mysql {
} }
pub fn channel_item(&mut self, channel_item_id: u64) -> Result<Option<ChannelItem>, Error> { pub fn channel_item(&mut self, channel_item_id: u64) -> Result<Option<ChannelItem>, Error> {
self.connection.exec_first( self.connection
"SELECT `channel_item_id`, `channel_id`, `pub_date`, `guid`, `link`, `title`, `description` FROM `channel_item` WHERE `channel_item_id` = ?", .exec_first(
(channel_item_id,) "SELECT `channel_item_id`,
).map(|row| { `channel_id`,
row.map(|(channel_item_id, channel_id, pub_date, guid, link, title, description)| { `pub_date`,
`guid`,
`link`,
`title`,
`description` FROM `channel_item` WHERE `channel_item_id` = ?",
(channel_item_id,),
)
.map(|row| {
row.map(
|(channel_item_id, channel_id, pub_date, guid, link, title, description)| {
ChannelItem { ChannelItem {
channel_item_id, channel_item_id,
channel_id, channel_id,
@ -57,7 +66,8 @@ impl Mysql {
title, title,
description, description,
} }
}) },
)
}) })
} }
@ -69,29 +79,24 @@ impl Mysql {
) -> Result<Vec<ChannelItem>, Error> { ) -> Result<Vec<ChannelItem>, Error> {
self.connection.exec_map( self.connection.exec_map(
format!( format!(
"SELECT `channel_item_id`, `channel_id`, `pub_date`, `guid`, `link`, `title`, `description` FROM `channel_item` WHERE `channel_id` = ? AND `guid` = ? LIMIT {}", "SELECT `channel_item_id`,
limit.unwrap_or(DEFAULT_LIMIT)), `channel_id`,
( `pub_date`,
channel_id, `guid`,
guid `link`,
`title`,
`description` FROM `channel_item` WHERE `channel_id` = ? AND `guid` = ? LIMIT {}",
limit.unwrap_or(DEFAULT_LIMIT)
), ),
|( (channel_id, guid),
|(channel_item_id, channel_id, pub_date, guid, link, title, description)| ChannelItem {
channel_item_id, channel_item_id,
channel_id, channel_id,
pub_date, pub_date,
guid, guid,
link, link,
title, title,
description description,
)|
ChannelItem {
channel_item_id,
channel_id,
pub_date,
guid,
link,
title,
description
}, },
) )
} }
@ -106,7 +111,12 @@ impl Mysql {
description: Option<&str>, description: Option<&str>,
) -> Result<u64, Error> { ) -> Result<u64, Error> {
self.connection.exec_drop( self.connection.exec_drop(
"INSERT INTO `channel_item` SET `channel_id` = ?, `pub_date` = ?, `guid` = ?, `link` = ?, `title` = ?, `description` = ?", "INSERT INTO `channel_item` SET `channel_id` = ?,
`pub_date` = ?,
`guid` = ?,
`link` = ?,
`title` = ?,
`description` = ?",
(channel_id, pub_date, guid, link, title, description), (channel_id, pub_date, guid, link, title, description),
)?; )?;
Ok(self.connection.last_insert_id()) Ok(self.connection.last_insert_id())
@ -115,10 +125,20 @@ impl Mysql {
pub fn contents(&mut self, limit: Option<usize>) -> Result<Vec<Content>, Error> { pub fn contents(&mut self, limit: Option<usize>) -> Result<Vec<Content>, Error> {
self.connection.query_map( self.connection.query_map(
format!( format!(
"SELECT `content_id`, `channel_item_id`, `source_id`, `title`, `description` FROM `content` LIMIT {}", "SELECT `content_id`,
`channel_item_id`,
`source_id`,
`title`,
`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 }, |(content_id, channel_item_id, source_id, title, description)| Content {
content_id,
channel_item_id,
source_id,
title,
description,
},
) )
} }
@ -130,7 +150,11 @@ impl Mysql {
) -> Result<Vec<Content>, Error> { ) -> Result<Vec<Content>, Error> {
self.connection.exec_map( self.connection.exec_map(
format!( format!(
"SELECT `content_id`, `channel_item_id`, `source_id`, `title`, `description` FROM `content` WHERE `channel_item_id` = ? AND `source_id` = ? LIMIT {}", "SELECT `content_id`,
`channel_item_id`,
`source_id`,
`title`,
`description` FROM `content` WHERE `channel_item_id` = ? AND `source_id` = ? LIMIT {}",
limit.unwrap_or(DEFAULT_LIMIT) limit.unwrap_or(DEFAULT_LIMIT)
), ),
(channel_item_id, source_id), (channel_item_id, source_id),