From c3a42da1d2fd08b8e1e3f071a7e8241be643fdd4 Mon Sep 17 00:00:00 2001 From: Kiana Sheibani Date: Sun, 27 Aug 2023 05:26:11 -0400 Subject: [PATCH] Add datasets module --- cli/src/dataset.rs | 0 cli/src/datasets.rs | 26 ++++++++++++++++++++++++++ cli/src/main.rs | 1 + 3 files changed, 27 insertions(+) delete mode 100644 cli/src/dataset.rs create mode 100644 cli/src/datasets.rs diff --git a/cli/src/dataset.rs b/cli/src/dataset.rs deleted file mode 100644 index e69de29..0000000 diff --git a/cli/src/datasets.rs b/cli/src/datasets.rs new file mode 100644 index 0000000..b0098e6 --- /dev/null +++ b/cli/src/datasets.rs @@ -0,0 +1,26 @@ +use sqlite::Connection; +use std::path::{Path, PathBuf}; + +/// Return the path to a dataset. +fn dataset_path(config_dir: &Path, dataset: &str) -> PathBuf { + let mut path = config_dir.to_owned(); + path.push("datasets"); + path.push(dataset); + path.set_extension("sqlite"); + path +} + +/// Create a new dataset given a path. +pub fn new_dataset(dataset: &Path) -> sqlite::Result { + let query = " + CREATE TABLE players ( + id INTEGER PRIMARY KEY ASC, + name TEXT, + elo REAL + ) STRICT; + "; + + let connection = sqlite::open(dataset)?; + connection.execute(query)?; + Ok(connection) +} diff --git a/cli/src/main.rs b/cli/src/main.rs index aab0b92..1a1eabb 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -8,6 +8,7 @@ mod queries; use queries::*; use search_games::{VideogameSearch, VideogameSearchVars}; +mod datasets; fn get_auth_key(config_dir: &Path) -> Option { use std::env::{var, VarError};