diff options
| author | Teddy Wing | 2021-05-30 17:47:19 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2021-05-30 17:47:19 +0200 | 
| commit | c6a4ecfde6034853ed2f8d13571170da69797835 (patch) | |
| tree | e3cc3b34b8e8ddb58ddfb9f43d37f4140d671c19 | |
| parent | 19273cac3a2fa9df71f663dbdb79ad63dea5bf65 (diff) | |
| download | reflectub-c6a4ecfde6034853ed2f8d13571170da69797835.tar.bz2 | |
database: Add repo description to `repositories` table
Store the repository description so we can check whether the description
was updated and copy it in our mirror accordingly.
| -rw-r--r-- | src/database.rs | 24 | 
1 files changed, 19 insertions, 5 deletions
| diff --git a/src/database.rs b/src/database.rs index c07eca0..9fa38fc 100644 --- a/src/database.rs +++ b/src/database.rs @@ -8,6 +8,7 @@ use crate::github;  pub struct Repo {      id: i64,      name: Option<String>, +    description: Option<String>,      updated_at: Option<String>,  } @@ -16,6 +17,7 @@ impl From<&github::Repo> for Repo {          Self {              id: repo.id,              name: Some(repo.name.clone()), +            description: repo.description.clone(),              updated_at: Some(repo.updated_at.clone()),          }      } @@ -54,6 +56,7 @@ impl Db {              CREATE TABLE repositories (                  id INTEGER PRIMARY KEY,                  name TEXT NOT NULL, +                description TEXT,                  updated_at TEXT NOT NULL              );          "#).await?; @@ -73,7 +76,11 @@ impl Db {          // NOTE: Returns `RowNotFound` if not found.          let row = sqlx::query(r#" -            SELECT id, name, updated_at +            SELECT +                id, +                name, +                description, +                updated_at              FROM repositories              WHERE id = ?          "#) @@ -87,7 +94,8 @@ impl Db {              Repo {                  id: row.get(0),                  name: Some(row.get(1)), -                updated_at: Some(row.get(2)), +                description: row.get(2), +                updated_at: Some(row.get(3)),              }          )      } @@ -97,12 +105,13 @@ impl Db {          sqlx::query(r#"              INSERT INTO repositories -                (id, name, updated_at) +                (id, name, description, updated_at)                  VALUES -                (?, ?, ?) +                (?, ?, ?, ?)          "#)              .bind(repo.id)              .bind(&repo.name) +            .bind(&repo.description)              .bind(&repo.updated_at)              .execute(&mut tx)              .await?; @@ -144,9 +153,14 @@ impl Db {          sqlx::query(r#"              UPDATE repositories -            SET updated_at = ? +            SET +                name = ? +                description = ? +                updated_at = ?              WHERE id = ?          "#) +            .bind(&repo.name) +            .bind(&repo.description)              .bind(&repo.updated_at)              .bind(repo.id)              .execute(&mut tx) | 
