From 5dc8a6d7667d1c35e8b903f0426cdaebba32e36e Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Tue, 3 Oct 2023 01:25:35 -0400 Subject: [PATCH] Make the dataset listing slightly more polished --- src/datasets.rs | 9 +++++++-- src/main.rs | 6 +++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/datasets.rs b/src/datasets.rs index 0cfd008..5459b76 100644 --- a/src/datasets.rs +++ b/src/datasets.rs @@ -9,6 +9,7 @@ use std::time::SystemTime; pub struct DatasetConfig { pub last_sync: Timestamp, pub game_id: VideogameId, + pub game_name: String, pub state: Option, } @@ -36,6 +37,7 @@ pub fn open_datasets(config_dir: &Path) -> sqlite::Result { name TEXT UNIQUE NOT NULL, last_sync INTEGER DEFAULT 1, game_id INTEGER NOT NULL, + game_name TEXT NOT NULL, state TEXT ) STRICT;"; @@ -71,7 +73,8 @@ pub fn new_dataset( dataset: &str, config: DatasetConfig, ) -> sqlite::Result<()> { - let query1 = r#"INSERT INTO datasets (name, game_id, state) VALUES (?, ?, ?)"#; + let query1 = r#"INSERT INTO datasets (name, game_id, game_name, state) + VALUES (?, ?, ?, ?)"#; let query2 = format!( r#" CREATE TABLE "dataset_{0}" ( id INTEGER PRIMARY KEY, @@ -87,7 +90,8 @@ pub fn new_dataset( .into_iter() .bind((1, dataset))? .bind((2, config.game_id.0 as i64))? - .bind((3, config.state.as_deref()))? + .bind((3, &config.game_name[..]))? + .bind((4, config.state.as_deref()))? .try_for_each(|x| x.map(|_| ()))?; connection.execute(query2) @@ -109,6 +113,7 @@ pub fn get_dataset_config( Ok(DatasetConfig { last_sync: Timestamp(r_.read::("last_sync") as u64), game_id: VideogameId(r_.read::("game_id") as u64), + game_name: r_.read::<&str, _>("game_name").to_owned(), state: r_.read::, _>("state").map(String::from), }) }) diff --git a/src/main.rs b/src/main.rs index 5a249e6..9501cda 100644 --- a/src/main.rs +++ b/src/main.rs @@ -171,7 +171,10 @@ fn dataset_new(name: Option, auth_token: Option) { error("Out of range!", 1); } - let game_id = games[index].id; + let VideogameData { + id: game_id, + name: game_name, + } = games[index].clone(); let connection = open_datasets(&config_dir).unwrap_or_else(|_| error("Could not open datasets file", 1)); @@ -181,6 +184,7 @@ fn dataset_new(name: Option, auth_token: Option) { DatasetConfig { last_sync: Timestamp(1), game_id, + game_name, state: None, }, )