diff --git a/koucha/src/db.rs b/koucha/src/db.rs index 6914cfa..d103e86 100644 --- a/koucha/src/db.rs +++ b/koucha/src/db.rs @@ -12,11 +12,10 @@ mod item; pub use item::Item; macro_rules! define_id { - ($name:ident) => { - #[derive(PartialEq, Debug, Copy, Clone)] - pub struct $name(i64); - impl From<$name> for i64 { fn from(id: $name) -> Self { id.0 } } - }; + ($name:ident) => { + #[derive(PartialEq, Debug, Copy, Clone)] + pub struct $name(i64); + }; } define_id!(UserId); diff --git a/koucha/src/db/channel.rs b/koucha/src/db/channel.rs index 6df59fb..d7dfca9 100644 --- a/koucha/src/db/channel.rs +++ b/koucha/src/db/channel.rs @@ -245,10 +245,7 @@ mod tests { let channel1 = Channel::get_or_create(pool, url_feed.clone()).await.unwrap(); let channel2 = Channel::get_or_create(pool, url_feed).await.unwrap(); - assert_eq!( - i64::from(channel1.id()), - i64::from(channel2.id()) - ); + assert_eq!(channel1.id(), channel2.id()); } #[tokio::test] diff --git a/koucha/src/db/feed.rs b/koucha/src/db/feed.rs index a769b1b..f3a8559 100644 --- a/koucha/src/db/feed.rs +++ b/koucha/src/db/feed.rs @@ -49,13 +49,12 @@ impl Feed { pub async fn create( pool: &AdapterPool, user_id: UserId, title: &str ) -> Result { - let int_id = i64::from(user_id); let new_feed = sqlx::query_as!( UnparsedFeed, "INSERT INTO feeds (user_id, title) VALUES (?, ?) RETURNING id as `id!`, title", - int_id, title + user_id.0, title ).fetch_one(&pool.0).await?.parse(); new_feed @@ -75,11 +74,10 @@ impl Feed { pub async fn add_channel( &self, pool: &AdapterPool, channel_id: ChannelId ) -> Result<()> { - let int_channel_id = i64::from(channel_id); sqlx::query!( "INSERT INTO feed_channels (feed_id, channel_id) VALUES (?, ?)", - self.id.0, int_channel_id + self.id.0, channel_id.0 ).execute(&pool.0).await?; Ok(()) diff --git a/koucha/src/db/feed_channel.rs b/koucha/src/db/feed_channel.rs index f8a3870..27e39f9 100644 --- a/koucha/src/db/feed_channel.rs +++ b/koucha/src/db/feed_channel.rs @@ -60,15 +60,14 @@ impl FeedChannel { async fn add_item_at( &self, pool: &AdapterPool, item: &Item, add_at: DateTime ) -> Result<()> { - let int_item_id = i64::from(item.id()); - let int_feed_id = i64::from(self.feed_id); + let int_item_id = item.id().0; let int_initial_score = i64::from(self.initial_score); let string_last_updated = add_at.to_rfc2822(); sqlx::query!( "INSERT OR IGNORE INTO feed_items (feed_id, item_id, score, last_updated) VALUES (?, ?, ?, ?)", - int_feed_id, int_item_id, int_initial_score, string_last_updated + self.feed_id.0, int_item_id, int_initial_score, string_last_updated ).execute(&pool.0).await?; Ok(()) } diff --git a/koucha/src/db/item.rs b/koucha/src/db/item.rs index cb25331..a910a14 100644 --- a/koucha/src/db/item.rs +++ b/koucha/src/db/item.rs @@ -58,7 +58,6 @@ impl Item { pub async fn get_or_create( pool: &AdapterPool, from_channel: ChannelId, guid: &str ) -> Result { - let int_channel_id = i64::from(from_channel); let item = sqlx::query_as!( UnparsedItem, @@ -67,7 +66,7 @@ impl Item { ON CONFLICT(channel_id, guid) DO UPDATE SET channel_id = channel_id RETURNING id as `id!`, channel_id, fetched_at, title, description, content", - int_channel_id, guid + from_channel.0, guid ).fetch_one(&pool.0).await?.parse(); item