Commit Diff


commit - 2ab001f29104a8d81ea06d7d6b57e19129c66b87
commit + b5eca9ca3490fd1dd3df30c8a31913bc80c36b94
blob - 10e7d3806f0b5bd09b66efddecdd8619e1e71b60
blob + e791b274d0d884818031b67854c71c4a44036760
--- src/db.rs
+++ src/db.rs
@@ -14,6 +14,7 @@ pub fn establish_connection() -> anyhow::Result<Sqlite
     Ok(SqliteConnection::establish(&database_url)?)
 }
 
+// inserts a new post or updates an old one with the same guid
 pub fn insert_post(conn: &SqliteConnection, item: &Item) -> anyhow::Result<usize> {
     let new_post = NewPost {
         guid: item.guid().ok_or(anyhow!("No guid found"))?.value(),
@@ -25,7 +26,7 @@ pub fn insert_post(conn: &SqliteConnection, item: &Ite
         content: item.content(),
     };
 
-    Ok(diesel::insert_into(posts::table)
+    Ok(diesel::replace_into(posts::table)
         .values(&new_post)
         .execute(conn)?)
 }