From ea0d3220db995018335c48eb06b9794235ff436b Mon Sep 17 00:00:00 2001 From: MetroWind Date: Sun, 7 Sep 2025 09:42:33 -0700 Subject: Initial commit, mostly just copied from shrt. --- src/data.hpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/data.hpp (limited to 'src/data.hpp') diff --git a/src/data.hpp b/src/data.hpp new file mode 100644 index 0000000..dc64e6f --- /dev/null +++ b/src/data.hpp @@ -0,0 +1,73 @@ +#pragma once + +#include +#include +#include +#include + +#include +#include +#include + +struct LinkItem +{ + enum Visibility {PUBLIC, PRIVATE}; + + int64_t id; + int64_t owner_id; + // Top-level items don’t have parents. + std::optional parent_id; + std::string name; + // If this is empty, it’s a parent. + std::string url; + std::string description; + Visibility visibility; + mw::Time time; +}; + +struct User +{ + int64_t id; + std::string openid_uid; + std::string name; +}; + +class DataSourceInterface +{ +public: + virtual ~DataSourceInterface() = default; + + // The schema version is the version of the database. It starts + // from 1. Every time the schema change, someone should increase + // this number by 1, manually, by hand. The intended use is to + // help with database migration. + virtual mw::E getSchemaVersion() const = 0; + + virtual std::vector items(std::optional parent) = 0; + +protected: + virtual mw::E setSchemaVersion(int64_t v) const = 0; +}; + +class DataSourceSQLite : public DataSourceInterface +{ +public: + explicit DataSourceSQLite(std::unique_ptr conn) + : db(std::move(conn)) {} + ~DataSourceSQLite() override = default; + + static mw::E> + fromFile(const std::string& db_file); + static mw::E> newFromMemory(); + + mw::E getSchemaVersion() const override; + + // Do not use. + DataSourceSQLite() = default; + +protected: + mw::E setSchemaVersion(int64_t v) const override; + +private: + std::unique_ptr db; +}; -- cgit v1.2.3-70-g09d2