Partial AppState rewrite

This commit is contained in:
micialware committed 2026-08-31 11:46:35 +03:00
1 parent 29a90d48d9
commit 0c4aec3dc0
13 files changed
+75 -49

No files matched your search

+27
View File
@@ -1,5 +1,6 @@
use crate::fs::*;
use rusqlite::Connection;
use std::ops::{Deref, DerefMut};
pub fn create_db() {
let db_file = db_path();
@@ -84,3 +85,29 @@ pub fn default_connection() -> Connection {
.expect("Failed to set PRAGMA");
connection
}
pub struct SqliteConnection(Option<Connection>);
impl Deref for SqliteConnection {
type Target = Connection;
fn deref(&self) -> &Self::Target {
self.0.as_ref().unwrap()
}
}
impl DerefMut for SqliteConnection {
fn deref_mut(&mut self) -> &mut Self::Target {
self.0.as_mut().unwrap()
}
}
impl Default for SqliteConnection {
fn default() -> Self {
SqliteConnection(Some(default_connection()))
}
}
impl SqliteConnection {
pub fn finish(&mut self) {
self.0 = None;
}
}