Remove from<i64> from db_ids
This commit is contained in:
parent
f2e00afbb9
commit
c3d9dff83f
5 changed files with 10 additions and 18 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -49,13 +49,12 @@ impl Feed {
|
|||
pub async fn create(
|
||||
pool: &AdapterPool, user_id: UserId, title: &str
|
||||
) -> Result<Self> {
|
||||
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(())
|
||||
|
|
|
|||
|
|
@ -60,15 +60,14 @@ impl FeedChannel {
|
|||
async fn add_item_at(
|
||||
&self, pool: &AdapterPool, item: &Item, add_at: DateTime<Utc>
|
||||
) -> 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(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,7 +58,6 @@ impl Item {
|
|||
pub async fn get_or_create(
|
||||
pool: &AdapterPool, from_channel: ChannelId, guid: &str
|
||||
) -> Result<Self> {
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue