Files
mini_projects/scryfall_deser/src/db.rs
Arthur Roberts 9c2d9c1fb7 Fixed matching the BulkType
The serde to_string thing has "" around the strings.
2025-08-16 02:21:43 +01:00

43 lines
1.1 KiB
Rust

use sqlite;
use std::fs;
use std::path::PathBuf;
use super::utils::get_local_cache_folder;
use super::utils::{create_cache_folder, get_local_data_folder, SQLITE_FILENAME};
fn get_local_data_sqlite_file() -> PathBuf {
let mut folder = get_local_data_folder();
folder.push(SQLITE_FILENAME);
folder
}
fn create_db_sql() -> String {
"
CREATE TABLE cards (
name TEXT NOT NULL UNIQUE,
type_line TEXT,
oracle_text TEXT,
power_toughness TEXT,
loyalty INTEGER,
legalities TEXT,
mana_cost TEXT,
scryfall_uri TEXT NOT NULL UNIQUE
);"
.to_string()
}
// Will delete your current db
pub fn init_db() -> bool {
create_cache_folder();
let sqlite_file = get_local_data_sqlite_file();
println!("sqlite file location: {}", sqlite_file.display());
// TESTING
println!("cache folder: {}", get_local_cache_folder().display());
let _res = fs::remove_file(&sqlite_file);
// TODO actually check result for whether it was a permissions thing or something
let connection = sqlite::open(sqlite_file).unwrap();
let init_query = create_db_sql();
connection.execute(init_query).unwrap();
true
}