Remove from<i64> from db_ids

This commit is contained in:
Julia Lange 2026-02-04 13:59:54 -08:00
parent f2e00afbb9
commit c3d9dff83f
Signed by: Julia
SSH key fingerprint: SHA256:5DJcfxa5/fKCYn57dcabJa2vN2e6eT0pBerYi5SUbto
5 changed files with 10 additions and 18 deletions

View file

@ -15,7 +15,6 @@ macro_rules! define_id {
($name:ident) => { ($name:ident) => {
#[derive(PartialEq, Debug, Copy, Clone)] #[derive(PartialEq, Debug, Copy, Clone)]
pub struct $name(i64); pub struct $name(i64);
impl From<$name> for i64 { fn from(id: $name) -> Self { id.0 } }
}; };
} }

View file

@ -245,10 +245,7 @@ mod tests {
let channel1 = Channel::get_or_create(pool, url_feed.clone()).await.unwrap(); let channel1 = Channel::get_or_create(pool, url_feed.clone()).await.unwrap();
let channel2 = Channel::get_or_create(pool, url_feed).await.unwrap(); let channel2 = Channel::get_or_create(pool, url_feed).await.unwrap();
assert_eq!( assert_eq!(channel1.id(), channel2.id());
i64::from(channel1.id()),
i64::from(channel2.id())
);
} }
#[tokio::test] #[tokio::test]

View file

@ -49,13 +49,12 @@ impl Feed {
pub async fn create( pub async fn create(
pool: &AdapterPool, user_id: UserId, title: &str pool: &AdapterPool, user_id: UserId, title: &str
) -> Result<Self> { ) -> Result<Self> {
let int_id = i64::from(user_id);
let new_feed = sqlx::query_as!( let new_feed = sqlx::query_as!(
UnparsedFeed, UnparsedFeed,
"INSERT INTO feeds (user_id, title) "INSERT INTO feeds (user_id, title)
VALUES (?, ?) VALUES (?, ?)
RETURNING id as `id!`, title", RETURNING id as `id!`, title",
int_id, title user_id.0, title
).fetch_one(&pool.0).await?.parse(); ).fetch_one(&pool.0).await?.parse();
new_feed new_feed
@ -75,11 +74,10 @@ impl Feed {
pub async fn add_channel( pub async fn add_channel(
&self, pool: &AdapterPool, channel_id: ChannelId &self, pool: &AdapterPool, channel_id: ChannelId
) -> Result<()> { ) -> Result<()> {
let int_channel_id = i64::from(channel_id);
sqlx::query!( sqlx::query!(
"INSERT INTO feed_channels (feed_id, channel_id) "INSERT INTO feed_channels (feed_id, channel_id)
VALUES (?, ?)", VALUES (?, ?)",
self.id.0, int_channel_id self.id.0, channel_id.0
).execute(&pool.0).await?; ).execute(&pool.0).await?;
Ok(()) Ok(())

View file

@ -60,15 +60,14 @@ impl FeedChannel {
async fn add_item_at( async fn add_item_at(
&self, pool: &AdapterPool, item: &Item, add_at: DateTime<Utc> &self, pool: &AdapterPool, item: &Item, add_at: DateTime<Utc>
) -> Result<()> { ) -> Result<()> {
let int_item_id = i64::from(item.id()); let int_item_id = item.id().0;
let int_feed_id = i64::from(self.feed_id);
let int_initial_score = i64::from(self.initial_score); let int_initial_score = i64::from(self.initial_score);
let string_last_updated = add_at.to_rfc2822(); let string_last_updated = add_at.to_rfc2822();
sqlx::query!( sqlx::query!(
"INSERT OR IGNORE INTO feed_items (feed_id, item_id, score, last_updated) "INSERT OR IGNORE INTO feed_items (feed_id, item_id, score, last_updated)
VALUES (?, ?, ?, ?)", 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?; ).execute(&pool.0).await?;
Ok(()) Ok(())
} }

View file

@ -58,7 +58,6 @@ impl Item {
pub async fn get_or_create( pub async fn get_or_create(
pool: &AdapterPool, from_channel: ChannelId, guid: &str pool: &AdapterPool, from_channel: ChannelId, guid: &str
) -> Result<Self> { ) -> Result<Self> {
let int_channel_id = i64::from(from_channel);
let item = sqlx::query_as!( let item = sqlx::query_as!(
UnparsedItem, UnparsedItem,
@ -67,7 +66,7 @@ impl Item {
ON CONFLICT(channel_id, guid) DO UPDATE SET channel_id = channel_id ON CONFLICT(channel_id, guid) DO UPDATE SET channel_id = channel_id
RETURNING id as `id!`, channel_id, fetched_at, title, description, RETURNING id as `id!`, channel_id, fetched_at, title, description,
content", content",
int_channel_id, guid from_channel.0, guid
).fetch_one(&pool.0).await?.parse(); ).fetch_one(&pool.0).await?.parse();
item item