From 16e6180ba7946119538d03463ea7d37fccc4dcb3 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Mon, 8 May 2023 13:38:36 +1000 Subject: Database init is now stable! --- src/database/include/database.hpp | 70 ++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 41 deletions(-) (limited to 'src/database/include/database.hpp') diff --git a/src/database/include/database.hpp b/src/database/include/database.hpp index 61918d96..6cdaaca6 100644 --- a/src/database/include/database.hpp +++ b/src/database/include/database.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -13,46 +14,37 @@ #include "leveldb/iterator.h" #include "leveldb/options.h" #include "leveldb/slice.h" +#include "records.hpp" #include "result.hpp" +#include "song.hpp" namespace database { -struct Artist { - std::string name; -}; - -struct Album { - std::string name; -}; - -typedef uint64_t SongId_t; - -struct Song { - std::string title; - uint64_t id; -}; - -struct SongMetadata {}; - typedef std::unique_ptr Continuation; +/* + * Wrapper for a set of results from the database. Owns the list of results, as + * well as a continuation token that can be used to continue fetching more + * results if they were paginated. + */ template class Result { public: - auto values() -> std::unique_ptr> { - return std::move(values_); - } + auto values() -> std::vector* { return values_.release(); } auto continuation() -> Continuation { return std::move(c_); } auto HasMore() -> bool { return c_->Valid(); } + Result(std::vector* values, Continuation c) + : values_(values), c_(std::move(c)) {} + Result(std::unique_ptr> values, Continuation c) : values_(std::move(values)), c_(std::move(c)) {} Result(Result&& other) - : values_(std::move(other.values_)), c_(std::move(other.c_)) {} + : values_(move(other.values_)), c_(std::move(other.c_)) {} Result operator=(Result&& other) { - return Result(other.values(), other.continuation()); + return Result(other.values(), std::move(other.continuation())); } Result(const Result&) = delete; @@ -73,30 +65,16 @@ class Database { ~Database(); - auto Populate() -> std::future; - - auto GetArtists(std::size_t page_size) -> std::future>; - auto GetMoreArtists(std::size_t page_size, Continuation c) - -> std::future>; - - auto GetAlbums(std::size_t page_size, std::optional artist) - -> std::future>; - auto GetMoreAlbums(std::size_t page_size, Continuation c) - -> std::future>; + auto Update() -> std::future; + auto Destroy() -> std::future; auto GetSongs(std::size_t page_size) -> std::future>; - auto GetSongs(std::size_t page_size, std::optional artist) - -> std::future>; - auto GetSongs(std::size_t page_size, - std::optional artist, - std::optional album) -> std::future>; auto GetMoreSongs(std::size_t page_size, Continuation c) -> std::future>; - auto GetSongIds(std::optional artist, std::optional album) - -> std::future>; - auto GetSongFilePath(SongId_t id) -> std::future>; - auto GetSongMetadata(SongId_t id) -> std::future>; + auto GetDump(std::size_t page_size) -> std::future>; + auto GetMoreDump(std::size_t page_size, Continuation c) + -> std::future>; Database(const Database&) = delete; Database& operator=(const Database&) = delete; @@ -107,6 +85,16 @@ class Database { Database(leveldb::DB* db, leveldb::Cache* cache); + auto dbMintNewSongId() -> SongId; + auto dbEntomb(SongId song, uint64_t hash) -> void; + + auto dbPutSongData(const SongData& s) -> void; + auto dbGetSongData(SongId id) -> std::optional; + auto dbPutHash(const uint64_t& hash, SongId i) -> void; + auto dbGetHash(const uint64_t& hash) -> std::optional; + auto dbPutSong(SongId id, const std::string& path, const uint64_t& hash) + -> void; + template using Parser = std::function(const leveldb::Slice& key, const leveldb::Slice& value)>; -- cgit v1.2.3