Merge branch 'master' of https://git.catherine-fc.com/hansoo/pokemon-data-displayer
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
all(not(debug_assertions), target_os = "windows"),
|
all(not(debug_assertions), target_os = "windows"),
|
||||||
windows_subsystem = "windows"
|
windows_subsystem = "windows"
|
||||||
)]
|
)]
|
||||||
|
use serde_json::json;
|
||||||
use wana_kana::to_katakana::*;
|
use wana_kana::to_katakana::*;
|
||||||
use wana_kana::to_hiragana::*;
|
use wana_kana::to_hiragana::*;
|
||||||
mod model;
|
mod model;
|
||||||
@@ -107,6 +108,31 @@ fn search_move(index: i64) -> MoveSearchResult {
|
|||||||
condition: None,
|
condition: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[tauri::command]
|
||||||
|
fn get_items() -> Vec<ItemSearchResult> {
|
||||||
|
let connection = sqlite::open("./pokemon.db").unwrap();
|
||||||
|
let query = "SELECT * FROM item WHERE 1";
|
||||||
|
let mut items: Vec<ItemSearchResult> = vec![];
|
||||||
|
for row in connection
|
||||||
|
.prepare(query)
|
||||||
|
.unwrap()
|
||||||
|
.into_iter()
|
||||||
|
.map(|row| row.unwrap())
|
||||||
|
{
|
||||||
|
let row_result = ItemSearchResult {
|
||||||
|
id: row.read::<i64, _>("id"),
|
||||||
|
name: row.read::<&str, _>("name").to_string(),
|
||||||
|
image: row.read::<&str, _>("image").to_string(),
|
||||||
|
effect: match row.read::<Option<&str>, _>("effect") {
|
||||||
|
Some(t) => Some(serde_json::from_str(t).unwrap_or(json!({}))),
|
||||||
|
_ => None,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
items.push(row_result);
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn search(index: i64) -> SearchResult {
|
fn search(index: i64) -> SearchResult {
|
||||||
let connection = sqlite::open("./pokemon.db").unwrap();
|
let connection = sqlite::open("./pokemon.db").unwrap();
|
||||||
@@ -173,7 +199,7 @@ fn search(index: i64) -> SearchResult {
|
|||||||
}
|
}
|
||||||
fn main() {
|
fn main() {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.invoke_handler(tauri::generate_handler![autosearch_move, search_move, autosearch, search])
|
.invoke_handler(tauri::generate_handler![autosearch_move, search_move, autosearch, search, get_items])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,3 +40,11 @@ pub struct Autosearch {
|
|||||||
pub id: i64,
|
pub id: i64,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||||
|
pub struct ItemSearchResult {
|
||||||
|
pub id: i64,
|
||||||
|
pub name: String,
|
||||||
|
pub image: String,
|
||||||
|
pub effect: Option<serde_json::Value>,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user