feat(backend): add sqlite migrations + app state + tests
这个提交包含在:
24
backend/include/csp/app_state.h
普通文件
24
backend/include/csp/app_state.h
普通文件
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "csp/db/sqlite_db.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace csp {
|
||||
|
||||
class AppState {
|
||||
public:
|
||||
static AppState& Instance();
|
||||
|
||||
void Init(const std::string& sqlite_path);
|
||||
|
||||
db::SqliteDb& db();
|
||||
|
||||
private:
|
||||
AppState() = default;
|
||||
|
||||
std::unique_ptr<db::SqliteDb> db_;
|
||||
};
|
||||
|
||||
} // namespace csp
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace csp::db {
|
||||
|
||||
class SqliteDb {
|
||||
public:
|
||||
static SqliteDb OpenFile(const std::string& path);
|
||||
static SqliteDb OpenMemory();
|
||||
|
||||
SqliteDb() = default;
|
||||
~SqliteDb();
|
||||
|
||||
SqliteDb(const SqliteDb&) = delete;
|
||||
SqliteDb& operator=(const SqliteDb&) = delete;
|
||||
|
||||
SqliteDb(SqliteDb&& other) noexcept;
|
||||
SqliteDb& operator=(SqliteDb&& other) noexcept;
|
||||
|
||||
sqlite3* raw() const { return db_; }
|
||||
|
||||
void Exec(const std::string& sql);
|
||||
|
||||
private:
|
||||
explicit SqliteDb(sqlite3* db) : db_(db) {}
|
||||
|
||||
sqlite3* db_ = nullptr;
|
||||
};
|
||||
|
||||
// Apply SQL migrations in order. For now we ship a single init migration.
|
||||
void ApplyMigrations(SqliteDb& db);
|
||||
|
||||
} // namespace csp::db
|
||||
在新工单中引用
屏蔽一个用户