mirror of
https://github.com/patarapolw/cjdic2.git
synced 2026-11-09 17:39:35 +00:00
db sub schema (via Arc)
This commit is contained in:
1 parent
442e309a81
commit
62cb1e5902
7 files changed
+368
-340
No files matched your search
+11
-4
@@ -1,24 +1,31 @@
|
||||
use std::{path::Path, sync::Mutex};
|
||||
use std::{
|
||||
path::Path,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use rusqlite::{Connection, Result};
|
||||
|
||||
use crate::models::Entry;
|
||||
|
||||
mod yomitan;
|
||||
pub use yomitan::{YomitanRow, create_schema, import_bundled_zip_file, search_yomitan};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Database {
|
||||
conn: Mutex<Connection>,
|
||||
pub(crate) conn: Arc<Mutex<Connection>>,
|
||||
}
|
||||
|
||||
impl Database {
|
||||
pub fn new<P: AsRef<Path>>(path: P) -> Result<Self> {
|
||||
let conn = Connection::open(path)?;
|
||||
Ok(Self {
|
||||
conn: Mutex::new(conn),
|
||||
conn: Arc::new(Mutex::new(conn)),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn yomitan(&self) -> yomitan::YomitanDatabase {
|
||||
yomitan::YomitanDatabase::new(self.clone())
|
||||
}
|
||||
|
||||
pub fn init(&self) -> Result<()> {
|
||||
let conn = self.conn.lock().unwrap();
|
||||
|
||||
|
||||
Reference in new issue
Block a user