diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 35ea20f..428a46e 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -2,50 +2,12 @@ all(not(debug_assertions), target_os = "windows"), windows_subsystem = "windows" )] -use serde::{Deserialize, Serialize}; use wana_kana::to_katakana::*; +mod model; +use model::*; -#[derive(Serialize, Deserialize, Debug, Clone)] -struct SearchResult { - id: i64, - name: String, - types: String, - hp: i64, - attack: i64, - defense: i64, - special_attack: i64, - special_defense: i64, - speed: i64, - abilities: String, - thumbnail: String, -} - -#[derive(Serialize, Deserialize, Debug, Clone)] -struct Autosearch { - id: i64, - name: String, -} -// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command -#[tauri::command] -fn greet(name: &str) -> String { - let connection = sqlite::open("./pokemon.db").unwrap(); - let query = "SELECT types FROM pokemon WHERE eng_name = ?"; - let mut result = "".to_string(); - for row in connection - .prepare(query) - .unwrap() - .into_iter() - .bind((1, name)) - .unwrap() - .map(|row| row.unwrap()) - { - result = row.read::<&str, _>("types").to_string(); - } - format!("Hello, {}! You've been greeted from Rust! {}", name, result) -} #[tauri::command] fn autosearch(keyword: &str) -> serde_json::Value { - let connection = sqlite::open("./pokemon.db").unwrap(); let query = "SELECT * FROM pokemon WHERE name like ? or name like ? LIMIT 5"; let mut result: Vec = vec![]; @@ -117,7 +79,7 @@ fn search(index: i64) -> SearchResult { } fn main() { tauri::Builder::default() - .invoke_handler(tauri::generate_handler![greet, autosearch, search]) + .invoke_handler(tauri::generate_handler![autosearch, search]) .run(tauri::generate_context!()) .expect("error while running tauri application"); } diff --git a/src-tauri/src/model.rs b/src-tauri/src/model.rs new file mode 100644 index 0000000..fb6e387 --- /dev/null +++ b/src-tauri/src/model.rs @@ -0,0 +1,22 @@ +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct SearchResult { + pub id: i64, + pub name: String, + pub types: String, + pub hp: i64, + pub attack: i64, + pub defense: i64, + pub special_attack: i64, + pub special_defense: i64, + pub speed: i64, + pub abilities: String, + pub thumbnail: String, +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct Autosearch { + pub id: i64, + pub name: String, +} \ No newline at end of file