Add datasets module
This commit is contained in:
parent
6eedd7cd4e
commit
c3a42da1d2
26
cli/src/datasets.rs
Normal file
26
cli/src/datasets.rs
Normal 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)
|
||||
}
|
|
@ -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};
|
||||
|
|
Loading…
Reference in a new issue