diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-06-23 15:32:11 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-06-23 15:32:11 +1000 |
| commit | 245d9ff4b9cde1f487beed76085a52f3f2d6d26c (patch) | |
| tree | 0730e6cda4c03a92c0d5e6b2e31fe27bfa021f69 /src/database/include/database.hpp | |
| parent | aee0474191aa6b4e4505e3f5a74b4ac8cc48063b (diff) | |
| download | tangara-fw-245d9ff4b9cde1f487beed76085a52f3f2d6d26c.tar.gz | |
add indexing to the database
idk man i wrote most of this in a fugue state whilst high on the couch
with my cat
Diffstat (limited to 'src/database/include/database.hpp')
| -rw-r--r-- | src/database/include/database.hpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/database/include/database.hpp b/src/database/include/database.hpp index 8fecc5f6..77a17b75 100644 --- a/src/database/include/database.hpp +++ b/src/database/include/database.hpp @@ -16,6 +16,7 @@ #include <vector> #include "file_gatherer.hpp" +#include "index.hpp" #include "leveldb/cache.h" #include "leveldb/db.h" #include "leveldb/iterator.h" @@ -23,6 +24,7 @@ #include "leveldb/slice.h" #include "records.hpp" #include "result.hpp" +#include "shared_string.h" #include "tag_parser.hpp" #include "tasks.hpp" #include "track.hpp" @@ -66,6 +68,20 @@ class Result { std::optional<Continuation<T>> prev_page_; }; +class IndexRecord { + public: + explicit IndexRecord(const IndexKey&, std::optional<Track>); + + auto text() const -> std::optional<shared_string>; + auto track() const -> std::optional<Track>; + + auto Expand(std::size_t) const -> std::optional<Continuation<IndexRecord>>; + + private: + IndexKey key_; + std::optional<Track> track_; +}; + class Database { public: enum DatabaseError { @@ -84,6 +100,9 @@ class Database { auto GetTrackPath(TrackId id) -> std::future<std::optional<std::string>>; + auto GetIndexes() -> std::vector<IndexInfo>; + auto GetTracksByIndex(const IndexInfo& index, std::size_t page_size) + -> std::future<Result<IndexRecord>*>; auto GetTracks(std::size_t page_size) -> std::future<Result<Track>*>; auto GetDump(std::size_t page_size) -> std::future<Result<std::string>*>; @@ -118,8 +137,7 @@ class Database { auto dbGetTrackData(TrackId id) -> std::optional<TrackData>; auto dbPutHash(const uint64_t& hash, TrackId i) -> void; auto dbGetHash(const uint64_t& hash) -> std::optional<TrackId>; - auto dbPutTrack(TrackId id, const std::string& path, const uint64_t& hash) - -> void; + auto dbCreateIndexesForTrack(Track track) -> void; template <typename T> auto dbGetPage(const Continuation<T>& c) -> Result<T>*; @@ -130,6 +148,10 @@ class Database { }; template <> +auto Database::ParseRecord<IndexRecord>(const leveldb::Slice& key, + const leveldb::Slice& val) + -> std::optional<IndexRecord>; +template <> auto Database::ParseRecord<Track>(const leveldb::Slice& key, const leveldb::Slice& val) -> std::optional<Track>; |
