From 4d4b7918726b4a56b87de8cdc577b6bf088c5f91 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sun, 30 May 2021 03:37:16 +0200 Subject: main: If repo was updated, save new `updated_at` value If the repo was updated since we last cached it, update the `updated_at` column to the new value so we know that we fetched the latest. --- src/database.rs | 16 +++++++++++++++- src/main.rs | 6 +++--- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/database.rs b/src/database.rs index e735df9..2a53f0b 100644 --- a/src/database.rs +++ b/src/database.rs @@ -139,7 +139,21 @@ impl Db { is_updated } - pub fn repo_update(repo: &Repo) -> Result<(), Error> { + pub async fn repo_update(&mut self, repo: &Repo) -> Result<(), Error> { + let mut tx = self.connection.begin().await?; + + sqlx::query(r#" + UPDATE repositories + SET updated_at = ? + WHERE id = ? + "#) + .bind(&repo.updated_at) + .bind(repo.id) + .execute(&mut tx) + .await?; + + tx.commit().await?; + Ok(()) } } diff --git a/src/main.rs b/src/main.rs index e7be108..cbaec61 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,10 +61,10 @@ async fn main() { match db.repo_get(id).await { Ok(r) => { - // TODO: fetch - if db.repo_is_updated(&db_repo).await.unwrap() { - dbg!("UPDATED", &db_repo); + // TODO: fetch + + db.repo_update(&db_repo).await.unwrap(); } }, -- cgit v1.2.3