aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2021-05-30 03:37:16 +0200
committerTeddy Wing2021-05-30 03:38:46 +0200
commit4d4b7918726b4a56b87de8cdc577b6bf088c5f91 (patch)
tree1d8a71ecd64cf6f2b42c57db37b6d7d3c97b3955
parenta879ee3ff4b73a013eb9303e5790c2a9df0a4f5b (diff)
downloadreflectub-4d4b7918726b4a56b87de8cdc577b6bf088c5f91.tar.bz2
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.
-rw-r--r--src/database.rs16
-rw-r--r--src/main.rs6
2 files changed, 18 insertions, 4 deletions
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();
}
},