Add datasets module

This commit is contained in:
Kiana Sheibani 2023-08-27 05:26:11 -04:00
parent 6eedd7cd4e
commit c3a42da1d2
Signed by: toki
GPG key ID: 6CB106C25E86A9F7
3 changed files with 27 additions and 0 deletions

View file

26
cli/src/datasets.rs Normal file
View file

@ -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<Connection> {
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)
}

View file

@ -8,6 +8,7 @@ mod queries;
use queries::*;
use search_games::{VideogameSearch, VideogameSearchVars};
mod datasets;
fn get_auth_key(config_dir: &Path) -> Option<String> {
use std::env::{var, VarError};