summaryrefslogtreecommitdiff
path: root/src/database/include/database.hpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-05-12 10:30:07 +1000
committerjacqueline <me@jacqueline.id.au>2023-05-12 10:30:07 +1000
commit961c8014ada037712e8c72f23430362e9f14c1ec (patch)
treece13e0a00fc0d0318d46e6dfbecf2360b4cc5e14 /src/database/include/database.hpp
parent10eb120878e01579bff2fdfab7bef59639b21155 (diff)
downloadtangara-fw-961c8014ada037712e8c72f23430362e9f14c1ec.tar.gz
Add some basic tests for the database
Diffstat (limited to 'src/database/include/database.hpp')
-rw-r--r--src/database/include/database.hpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/database/include/database.hpp b/src/database/include/database.hpp
index 6cdaaca6..29872e8d 100644
--- a/src/database/include/database.hpp
+++ b/src/database/include/database.hpp
@@ -9,6 +9,7 @@
#include <utility>
#include <vector>
+#include "file_gatherer.hpp"
#include "leveldb/cache.h"
#include "leveldb/db.h"
#include "leveldb/iterator.h"
@@ -17,6 +18,7 @@
#include "records.hpp"
#include "result.hpp"
#include "song.hpp"
+#include "tag_parser.hpp"
namespace database {
@@ -61,12 +63,15 @@ class Database {
ALREADY_OPEN,
FAILED_TO_OPEN,
};
+ static auto Open(IFileGatherer* file_gatherer, ITagParser* tag_parser)
+ -> cpp::result<Database*, DatabaseError>;
static auto Open() -> cpp::result<Database*, DatabaseError>;
+ static auto Destroy() -> void;
+
~Database();
auto Update() -> std::future<void>;
- auto Destroy() -> std::future<void>;
auto GetSongs(std::size_t page_size) -> std::future<Result<Song>>;
auto GetMoreSongs(std::size_t page_size, Continuation c)
@@ -80,10 +85,19 @@ class Database {
Database& operator=(const Database&) = delete;
private:
- std::unique_ptr<leveldb::DB> db_;
- std::unique_ptr<leveldb::Cache> cache_;
-
- Database(leveldb::DB* db, leveldb::Cache* cache);
+ // Owned. Dumb pointers because destruction needs to be done in an explicit
+ // order.
+ leveldb::DB* db_;
+ leveldb::Cache* cache_;
+
+ // Not owned.
+ IFileGatherer* file_gatherer_;
+ ITagParser* tag_parser_;
+
+ Database(leveldb::DB* db,
+ leveldb::Cache* cache,
+ IFileGatherer* file_gatherer,
+ ITagParser* tag_parser);
auto dbMintNewSongId() -> SongId;
auto dbEntomb(SongId song, uint64_t hash) -> void;