StartRNR/cli/src/datasets.rs

27 lines
656 B
Rust
Raw Normal View History

2023-08-27 05:26:11 -04:00
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)
}