feat(backend): add sqlite migrations + app state + tests

这个提交包含在:
anygen-build-bot
2026-02-12 08:58:53 +00:00
父节点 b6befe69f9
当前提交 76b512939d
修改 8 个文件,包含 334 行新增5 行删除

查看文件

@@ -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