separated model into separate file
This commit is contained in:
@@ -2,50 +2,12 @@
|
|||||||
all(not(debug_assertions), target_os = "windows"),
|
all(not(debug_assertions), target_os = "windows"),
|
||||||
windows_subsystem = "windows"
|
windows_subsystem = "windows"
|
||||||
)]
|
)]
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use wana_kana::to_katakana::*;
|
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]
|
#[tauri::command]
|
||||||
fn autosearch(keyword: &str) -> serde_json::Value {
|
fn autosearch(keyword: &str) -> serde_json::Value {
|
||||||
|
|
||||||
let connection = sqlite::open("./pokemon.db").unwrap();
|
let connection = sqlite::open("./pokemon.db").unwrap();
|
||||||
let query = "SELECT * FROM pokemon WHERE name like ? or name like ? LIMIT 5";
|
let query = "SELECT * FROM pokemon WHERE name like ? or name like ? LIMIT 5";
|
||||||
let mut result: Vec<Autosearch> = vec![];
|
let mut result: Vec<Autosearch> = vec![];
|
||||||
@@ -117,7 +79,7 @@ fn search(index: i64) -> SearchResult {
|
|||||||
}
|
}
|
||||||
fn main() {
|
fn main() {
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.invoke_handler(tauri::generate_handler![greet, autosearch, search])
|
.invoke_handler(tauri::generate_handler![autosearch, search])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
}
|
}
|
||||||
|
|||||||
22
src-tauri/src/model.rs
Normal file
22
src-tauri/src/model.rs
Normal file
@@ -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,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user