pref: 缓存显示器参数读数。#5.
This commit is contained in:
25
src-tauri/src/db/db.rs
Normal file
25
src-tauri/src/db/db.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use std::env::current_dir;
|
||||
|
||||
use once_cell::sync::OnceCell;
|
||||
use redb::Database;
|
||||
use tauri::api::path::config_dir;
|
||||
|
||||
use crate::picker;
|
||||
|
||||
trait GlobalDatabase<T> {
|
||||
fn global() -> &'static T;
|
||||
}
|
||||
|
||||
impl GlobalDatabase<Database> for Database {
|
||||
fn global() -> &'static Database {
|
||||
static GLOBAL_DATABASE: OnceCell<Database> = OnceCell::new();
|
||||
|
||||
GLOBAL_DATABASE.get_or_init(|| {
|
||||
let path = config_dir()
|
||||
.unwrap_or(current_dir().unwrap())
|
||||
.join("main.redb");
|
||||
let db = Database::create(path).unwrap();
|
||||
return db;
|
||||
})
|
||||
}
|
||||
}
|
3
src-tauri/src/db/mod.rs
Normal file
3
src-tauri/src/db/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
mod db;
|
||||
|
||||
pub use db::*;
|
Reference in New Issue
Block a user