mirror of
https://github.com/patarapolw/cjdic2.git
synced 2026-11-09 17:39:35 +00:00
consume core in Tauri
This commit is contained in:
1 parent
876b879a65
commit
59968e0d6c
14 files changed
+157
-75
No files matched your search
@@ -0,0 +1,24 @@
|
||||
use std::path::Path;
|
||||
|
||||
use crate::{db::Database, error::CJDicError, models::Entry};
|
||||
|
||||
pub struct AppService {
|
||||
db: Database,
|
||||
}
|
||||
|
||||
impl AppService {
|
||||
pub fn new<P: AsRef<Path>>(db_path: P) -> Result<Self, CJDicError> {
|
||||
let db = Database::new(db_path)?;
|
||||
db.init()?;
|
||||
Ok(Self { db })
|
||||
}
|
||||
|
||||
pub fn add_entry(&self, word: &str, definition: &str) -> Result<(), CJDicError> {
|
||||
self.db.insert_entry(word, definition)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn list_entries(&self) -> Result<Vec<Entry>, CJDicError> {
|
||||
Ok(self.db.fetch_all_entries()?)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user