modified data type for new data schema
This commit is contained in:
@@ -8,9 +8,7 @@ use wana_kana::to_katakana::*;
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
struct SearchResult {
|
||||
id: i64,
|
||||
dex_index: String,
|
||||
jap_name: String,
|
||||
eng_name: String,
|
||||
name: String,
|
||||
types: String,
|
||||
hp: i64,
|
||||
attack: i64,
|
||||
@@ -18,8 +16,8 @@ struct SearchResult {
|
||||
special_attack: i64,
|
||||
special_defense: i64,
|
||||
speed: i64,
|
||||
thumb_small: String,
|
||||
thumb_big: String,
|
||||
abilities: String,
|
||||
thumbnail: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
@@ -49,7 +47,7 @@ fn greet(name: &str) -> String {
|
||||
fn autosearch(keyword: &str) -> serde_json::Value {
|
||||
|
||||
let connection = sqlite::open("./pokemon.db").unwrap();
|
||||
let query = "SELECT * FROM pokemon WHERE LOWER(eng_name) like ? or jap_name like ? or jap_name like ? or LOWER(dex_index) like ? LIMIT 5";
|
||||
let query = "SELECT * FROM pokemon WHERE name like ? or name like ? LIMIT 5";
|
||||
let mut result: Vec<Autosearch> = vec![];
|
||||
let aste_keyword = format!("%{}%", keyword.to_lowercase());
|
||||
let katakana = format!("%{}%", to_katakana(keyword));
|
||||
@@ -60,21 +58,15 @@ fn autosearch(keyword: &str) -> serde_json::Value {
|
||||
.into_iter()
|
||||
.bind((1, aste_keyword.as_str()))
|
||||
.unwrap()
|
||||
.bind((2, aste_keyword.as_str()))
|
||||
.unwrap()
|
||||
.bind((3, katakana.as_str()))
|
||||
.unwrap()
|
||||
.bind((4, aste_keyword.as_str()))
|
||||
.bind((2, katakana.as_str()))
|
||||
.unwrap()
|
||||
.map(|row| row.unwrap())
|
||||
{
|
||||
let row_result = Autosearch {
|
||||
id: row.read::<i64, _>("id"),
|
||||
name: format!(
|
||||
"{} - {} ({})",
|
||||
row.read::<&str, _>("dex_index").to_string(),
|
||||
row.read::<&str, _>("jap_name").to_string(),
|
||||
row.read::<&str, _>("eng_name").to_string()
|
||||
"{}",
|
||||
row.read::<&str, _>("name").to_string()
|
||||
),
|
||||
};
|
||||
result.push(row_result);
|
||||
@@ -96,12 +88,10 @@ fn search(index: i64) -> SearchResult {
|
||||
{
|
||||
let row_result = SearchResult {
|
||||
id: row.read::<i64, _>("id"),
|
||||
dex_index: row.read::<&str, _>("dex_index").to_string(),
|
||||
eng_name: row.read::<&str, _>("eng_name").to_string(),
|
||||
jap_name: row.read::<&str, _>("jap_name").to_string(),
|
||||
name: row.read::<&str, _>("name").to_string(),
|
||||
types: row.read::<&str, _>("types").to_string(),
|
||||
thumb_big: row.read::<&str, _>("thumb_big").to_string(),
|
||||
thumb_small: row.read::<&str, _>("thumb_small").to_string(),
|
||||
thumbnail: row.read::<&str, _>("thumbnail").to_string(),
|
||||
abilities: row.read::<&str, _>("abilities").to_string(),
|
||||
hp: row.read::<i64, _>("hp"),
|
||||
attack: row.read::<i64, _>("attack"),
|
||||
defense: row.read::<i64, _>("defense"),
|
||||
@@ -113,12 +103,10 @@ fn search(index: i64) -> SearchResult {
|
||||
}
|
||||
return SearchResult {
|
||||
id: 0,
|
||||
dex_index: "#???".to_string(),
|
||||
eng_name: "Missigno".to_string(),
|
||||
jap_name: "Missigno".to_string(),
|
||||
name: "Missigno".to_string(),
|
||||
types: "[]".to_string(),
|
||||
thumb_big: "".to_string(),
|
||||
thumb_small: "".to_string(),
|
||||
thumbnail: "".to_string(),
|
||||
abilities: "{}".to_string(),
|
||||
hp: 0,
|
||||
attack: 0,
|
||||
defense: 0,
|
||||
|
||||
Reference in New Issue
Block a user