feat(backend): add sqlite migrations + app state + tests
这个提交包含在:
22
backend/src/app_state.cc
普通文件
22
backend/src/app_state.cc
普通文件
@@ -0,0 +1,22 @@
|
||||
#include "csp/app_state.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
namespace csp {
|
||||
|
||||
AppState& AppState::Instance() {
|
||||
static AppState inst;
|
||||
return inst;
|
||||
}
|
||||
|
||||
void AppState::Init(const std::string& sqlite_path) {
|
||||
db_ = std::make_unique<db::SqliteDb>(db::SqliteDb::OpenFile(sqlite_path));
|
||||
csp::db::ApplyMigrations(*db_);
|
||||
}
|
||||
|
||||
csp::db::SqliteDb& AppState::db() {
|
||||
if (!db_) throw std::runtime_error("AppState not initialized");
|
||||
return *db_;
|
||||
}
|
||||
|
||||
} // namespace csp
|
||||
在新工单中引用
屏蔽一个用户