refactor(core): integrate SQLite database into application core

- Initialize database on app startup with migration from JSON config
- Update AppState to include Database instance alongside MultiAppConfig
- Simplify store module by removing unused session management code
- Add database initialization to app setup flow
- Support both database and legacy config during transition
This commit is contained in:
YoVinchen
2025-11-22 23:26:41 +08:00
parent 5d1eed563d
commit 529051f0e8
4 changed files with 57 additions and 54 deletions

View File

@@ -1,26 +1,14 @@
use crate::app_config::MultiAppConfig;
use crate::error::AppError;
use std::sync::RwLock;
use crate::database::Database;
use std::sync::Arc;
/// 全局应用状态
pub struct AppState {
pub config: RwLock<MultiAppConfig>,
pub db: Arc<Database>,
}
impl AppState {
/// 创建新的应用状态
/// 注意:仅在配置成功加载时返回;不会在失败时回退默认值。
pub fn try_new() -> Result<Self, AppError> {
let config = MultiAppConfig::load()?;
Ok(Self {
config: RwLock::new(config),
})
}
/// 保存配置到文件
pub fn save(&self) -> Result<(), AppError> {
let config = self.config.read().map_err(AppError::from)?;
config.save()
pub fn new(db: Arc<Database>) -> Self {
Self { db }
}
}