Got all cards out from db
This commit is contained in:
@@ -26,6 +26,18 @@ CREATE TABLE cards (
|
||||
.to_string()
|
||||
}
|
||||
|
||||
pub fn get_all_card_names() -> Vec<String> {
|
||||
let sqlite_file = get_local_data_sqlite_file();
|
||||
let conn = rusqlite::Connection::open(sqlite_file).unwrap();
|
||||
let mut stmt = conn.prepare("SELECT name FROM cards;").unwrap();
|
||||
let mut rows = stmt.query([]).unwrap();
|
||||
let mut card_names = Vec::new();
|
||||
while let Some(row) = rows.next().unwrap() {
|
||||
card_names.push(row.get(0).unwrap());
|
||||
}
|
||||
card_names
|
||||
}
|
||||
|
||||
pub fn update_db_with_file(file: PathBuf) -> bool {
|
||||
let ac = fs::read_to_string(file).unwrap();
|
||||
let ac: Vec<ScryfallCard> = serde_json::from_str(&ac).unwrap();
|
||||
|
||||
@@ -5,7 +5,7 @@ mod deser;
|
||||
pub use crate::deser::ScryfallCard;
|
||||
|
||||
mod db;
|
||||
pub use db::{init_db, update_db_with_file};
|
||||
pub use db::{get_all_card_names, init_db, update_db_with_file};
|
||||
|
||||
mod utils;
|
||||
pub use utils::get_local_cache_folder;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
use clap::Parser;
|
||||
use scryfall_deser::get_all_card_names;
|
||||
use scryfall_deser::get_local_cache_folder;
|
||||
use scryfall_deser::init_db;
|
||||
use scryfall_deser::update_db_with_file;
|
||||
@@ -14,7 +15,11 @@ struct Args {
|
||||
fn main() {
|
||||
let args = Args::parse();
|
||||
if args.update {
|
||||
unimplemented!("Haven't implemented update yet");
|
||||
init_db();
|
||||
let mut path = get_local_cache_folder();
|
||||
// TODO - actually download and update
|
||||
path.push("oracle-cards-20250814210711.json");
|
||||
update_db_with_file(path);
|
||||
}
|
||||
let card_name = args.remainder;
|
||||
if card_name.is_empty() {
|
||||
@@ -22,9 +27,6 @@ fn main() {
|
||||
}
|
||||
let search_string = card_name.join(" ");
|
||||
dbg!(search_string);
|
||||
|
||||
init_db();
|
||||
let mut path = get_local_cache_folder();
|
||||
path.push("oracle-cards-20250814210711.json");
|
||||
update_db_with_file(path);
|
||||
let cards = get_all_card_names();
|
||||
dbg!(cards);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user