文件
csp/backend/src/app_state.cc

28 行
603 B
C++

#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) {
if (sqlite_path == ":memory:") {
db_ = std::make_unique<db::SqliteDb>(db::SqliteDb::OpenMemory());
} else {
db_ = std::make_unique<db::SqliteDb>(db::SqliteDb::OpenFile(sqlite_path));
}
csp::db::ApplyMigrations(*db_);
csp::db::SeedDemoData(*db_);
}
csp::db::SqliteDb& AppState::db() {
if (!db_) throw std::runtime_error("AppState not initialized");
return *db_;
}
} // namespace csp