expose to Tauri to ensure it works

This commit is contained in:
polv committed 2026-02-23 05:17:51 +07:00
1 parent 62cb1e5902
commit 098ee45b81
12 files changed
+108 -53

No files matched your search

+6 -3
View File
@@ -7,10 +7,13 @@ use std::{
use anyhow::{Context, Ok};
use cjdic2_core::db::Database;
fn main() -> Result<(), anyhow::Error> {
let db = Database::new("test.db")?;
mod common;
use common::get_db_path;
let zip_dir = Path::new("src-tauri/resources/yomitan");
fn main() -> Result<(), anyhow::Error> {
let db = Database::new(get_db_path())?;
let zip_dir = Path::new("tmp/yomitan");
println!("zip_dir: {:?}", absolute(zip_dir)); // Relative to workspace root
for entry in
+5
View File
@@ -0,0 +1,5 @@
use std::path::PathBuf;
pub fn get_db_path() -> PathBuf {
PathBuf::from("test.db")
}
+4 -1
View File
@@ -3,8 +3,11 @@ use std::time::Instant;
use anyhow::Ok;
use cjdic2_core::db::Database;
mod common;
use common::get_db_path;
fn main() -> Result<(), anyhow::Error> {
let db = Database::new("test.db")?;
let db = Database::new(get_db_path())?;
let start = Instant::now();
let rs = db.yomitan().search_yomitan("擦る", "する", 10, 0)?;
+4 -1
View File
@@ -3,8 +3,11 @@ use std::time::Instant;
use anyhow::Ok;
use cjdic2_core::db::Database;
mod common;
use common::get_db_path;
fn main() -> Result<(), anyhow::Error> {
let db = Database::new("test.db")?;
let db = Database::new(get_db_path())?;
let start = Instant::now();
db.yomitan().create_schema()?;
+1
View File
@@ -8,6 +8,7 @@ use rusqlite::{Connection, Result};
use crate::models::Entry;
mod yomitan;
pub use yomitan::{YomitanRow, YomitanZipImportResult};
#[derive(Clone)]
pub struct Database {
+20 -20
View File
@@ -13,6 +13,26 @@ fn blake3_hex(s: &str) -> String {
format!("{}", hash(s.as_bytes()))
}
#[derive(Serialize, Debug)]
pub struct YomitanZipImportResult {
exists: bool,
load: bool,
error: Option<String>,
}
#[derive(Serialize, Debug)]
pub struct YomitanRow {
term: String,
reading: String,
def_tags: String,
rules: String,
score: i64,
glossary_json: String,
sequence: Option<i64>,
term_tags: String,
dict_title: String,
}
pub struct YomitanDatabase {
db: Database,
}
@@ -453,23 +473,3 @@ fn intern(
cache.insert(value.to_string(), id);
Ok(id)
}
#[derive(Serialize, Debug)]
pub struct YomitanZipImportResult {
exists: bool,
load: bool,
error: Option<String>,
}
#[derive(Serialize, Debug)]
pub struct YomitanRow {
term: String,
reading: String,
def_tags: String,
rules: String,
score: i64,
glossary_json: String,
sequence: Option<i64>,
term_tags: String,
dict_title: String,
}
+12 -3
View File
@@ -1,6 +1,6 @@
use std::path::Path;
use crate::{db::Database, error::CJDicError, models::Entry};
use crate::{db::Database, db::YomitanRow, error::CJDicError, models::Entry};
pub struct AppService {
db: Database,
@@ -22,7 +22,16 @@ impl AppService {
Ok(self.db.fetch_all_entries()?)
}
pub fn search_yomitan(&self, _term: &str, _reading: &str) -> Result<(), CJDicError> {
Ok(())
pub fn search_yomitan(
&self,
q_term: &str,
q_reading: &str,
limit: u32,
offset: u32,
) -> Result<Vec<YomitanRow>, CJDicError> {
Ok(self
.db
.yomitan()
.search_yomitan(q_term, q_reading, limit, offset)?)
}
}