Changing how to use textdifference thing
I think it'd be better to use text difference if a substring isn't found. I realised afterwards that I think this is how Scryfall does it anyway.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use rusqlite;
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::str::SplitWhitespace;
|
||||
|
||||
use super::deser::ScryfallCard;
|
||||
use super::utils::get_local_cache_folder;
|
||||
@@ -12,21 +13,6 @@ fn get_local_data_sqlite_file() -> PathBuf {
|
||||
folder
|
||||
}
|
||||
|
||||
fn create_db_sql() -> String {
|
||||
"
|
||||
CREATE TABLE cards (
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
lowercase_name TEXT NOT NULL UNIQUE,
|
||||
type_line TEXT,
|
||||
oracle_text TEXT,
|
||||
power_toughness TEXT,
|
||||
loyalty INTEGER,
|
||||
mana_cost TEXT,
|
||||
scryfall_uri TEXT NOT NULL UNIQUE
|
||||
);"
|
||||
.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();
|
||||
@@ -58,6 +44,13 @@ pub fn update_db_with_file(file: PathBuf) -> bool {
|
||||
let mut conn = rusqlite::Connection::open(sqlite_file).unwrap();
|
||||
let tx = conn.transaction().unwrap();
|
||||
for card in ac {
|
||||
for word in card.name.split_whitespace() {
|
||||
let res = tx.execute(
|
||||
"INSERT INTO magic_words (word) VALUES (?1)
|
||||
ON CONFLICT (word) DO NOTHING;",
|
||||
[word.replace(",", "")],
|
||||
);
|
||||
}
|
||||
let lowercase_name = card.name.to_lowercase();
|
||||
let power_toughness = match card.power {
|
||||
Some(p) => format!("{}/{}", p, card.toughness.unwrap()),
|
||||
@@ -84,6 +77,23 @@ pub fn update_db_with_file(file: PathBuf) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
const CREATE_CARDS_TABLE_SQL: &str = "
|
||||
CREATE TABLE cards (
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
lowercase_name TEXT NOT NULL UNIQUE,
|
||||
type_line TEXT,
|
||||
oracle_text TEXT,
|
||||
power_toughness TEXT,
|
||||
loyalty INTEGER,
|
||||
mana_cost TEXT,
|
||||
scryfall_uri TEXT NOT NULL UNIQUE
|
||||
)";
|
||||
|
||||
const CREATE_MAGIC_WORDS_TABLE_SQL: &str = "
|
||||
CREATE TABLE magic_words (
|
||||
word TEXT NOT NULL UNIQUE
|
||||
)";
|
||||
|
||||
// Will delete your current db
|
||||
pub fn init_db() -> bool {
|
||||
create_cache_folder();
|
||||
@@ -94,7 +104,9 @@ pub fn init_db() -> bool {
|
||||
let _res = fs::remove_file(&sqlite_file);
|
||||
// TODO actually check result for whether it was a permissions thing or something
|
||||
let connection = rusqlite::Connection::open(sqlite_file).unwrap();
|
||||
let init_query = create_db_sql();
|
||||
connection.execute(&init_query, ()).unwrap();
|
||||
connection.execute(&CREATE_CARDS_TABLE_SQL, ()).unwrap();
|
||||
connection
|
||||
.execute(&CREATE_MAGIC_WORDS_TABLE_SQL, ())
|
||||
.unwrap();
|
||||
true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user