summaryrefslogtreecommitdiff
path: root/src/database/include
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-04-26 12:27:11 +1000
committerjacqueline <me@jacqueline.id.au>2023-04-26 12:27:28 +1000
commit083f4011aa740d492d9a9ceb07c7228003f5ad39 (patch)
tree29a9fc9bcaec0ba24c27067f65772270d0273a72 /src/database/include
parent2be4d4204c6cb3a591be070e5d6a15a54070fc6c (diff)
downloadtangara-fw-083f4011aa740d492d9a9ceb07c7228003f5ad39.tar.gz
removed unused raw db stuff
Diffstat (limited to 'src/database/include')
-rw-r--r--src/database/include/database.hpp3
-rw-r--r--src/database/include/table.hpp87
-rw-r--r--src/database/include/table_reader.hpp53
-rw-r--r--src/database/include/table_writer.hpp5
4 files changed, 3 insertions, 145 deletions
diff --git a/src/database/include/database.hpp b/src/database/include/database.hpp
index cfef0a7d..b9df5fd4 100644
--- a/src/database/include/database.hpp
+++ b/src/database/include/database.hpp
@@ -17,6 +17,9 @@ class Database {
~Database();
+ auto Initialise() -> void;
+ auto Update() -> void;
+
private:
std::unique_ptr<leveldb::DB> db_;
std::unique_ptr<leveldb::Cache> cache_;
diff --git a/src/database/include/table.hpp b/src/database/include/table.hpp
deleted file mode 100644
index 438c23b6..00000000
--- a/src/database/include/table.hpp
+++ /dev/null
@@ -1,87 +0,0 @@
-#pragma once
-
-#include <cstddef>
-#include <cstdint>
-#include <memory>
-#include <optional>
-#include <string>
-#include <utility>
-
-#include "esp32/himem.h"
-#include "ff.h"
-#include "span.hpp"
-#include "sys/_stdint.h"
-
-namespace database {
-
-// Types used for indexing into files on disk. These should, at minimum, match
-// the size of the types that the underlying filesystem uses to address within
-// files. FAT32 uses 32 bit address. If we drop this and just support exFAT, we
-// can change these to 64 bit types.
-typedef uint32_t Index_t;
-typedef Index_t IndexOffset_t;
-
-// The amount of memory that will be used to page database columns in from disk.
-// Currently we only use a single 'page' in PSRAM per column, but with some
-// refactoring we could easily page more.
-// Keep this value 32KiB-aligned for himem compatibility.
-extern const std::size_t kRamBlockSize;
-
-struct DatabaseHeader {
- uint32_t magic_number;
- uint16_t db_version;
- Index_t num_indices;
-};
-
-struct DatabaseEntry {
- uint8_t type;
- std::string path;
-
- std::string title;
- std::string album;
- std::string artist;
- std::string album_artist;
-};
-
-struct IndexEntry {
- uint8_t type;
- IndexOffset_t path;
-
- IndexOffset_t title;
- IndexOffset_t album;
- IndexOffset_t artist;
- IndexOffset_t album_artist;
-};
-
-struct RowData {
- std::unique_ptr<std::byte[]> arr;
- std::size_t length;
-};
-
-// Representation of a single column of data. Each column is simply a tightly
-// packed list of [size, [bytes, ...]] pairs. Callers are responsible for
-// parsing and encoding the actual bytes themselves.
-class Column {
- public:
- static auto Open(std::string) -> std::optional<Column>;
-
- Column(FIL file, std::size_t file_size);
- ~Column();
-
- auto ReadDataAtOffset(esp_himem_rangehandle_t, IndexOffset_t) -> RowData;
- auto AppendRow(cpp::span<std::byte> row) -> bool;
- auto FlushChanges() -> void;
-
- private:
- FIL file_;
- IndexOffset_t length_;
-
- esp_himem_handle_t block_;
- std::pair<IndexOffset_t, IndexOffset_t> loaded_range_;
-
- auto IsOffsetLoaded(IndexOffset_t offset) -> bool;
- auto LoadOffsetFromDisk(cpp::span<std::byte> dest, IndexOffset_t offset)
- -> bool;
-};
-
-} // namespace database
diff --git a/src/database/include/table_reader.hpp b/src/database/include/table_reader.hpp
deleted file mode 100644
index 9f7cc4ee..00000000
--- a/src/database/include/table_reader.hpp
+++ /dev/null
@@ -1,53 +0,0 @@
-#pragma once
-
-#include <string>
-
-#include "result.hpp"
-#include "span.hpp"
-
-#include "table.hpp"
-
-namespace database {
-
-class TableReader {
- public:
- enum ReadError {
- OUT_OF_RANGE,
- IO_ERROR,
- PARSE_ERROR,
- };
-
- auto ReadEntryAtIndex(Index_t index) -> cpp::result<DatabaseEntry, ReadError>;
-
- template <typename T>
- auto ReadColumnOffsetAtIndex(Column<T> col, Index_t index)
- -> cpp::result<IndexOffset_t, ReadError>;
-
- template <typename T>
- auto ParseColumnAtIndex(Column<T> col, Index_t index)
- -> cpp::result<T, ReadError> {
- return ReadColumnOffsetAtIndex(col, index).map([&](IndexOffset_t offset) {
- return ReadColumnAtOffset(col, offset);
- });
- }
-
- template <typename T>
- auto ParseColumnAtOffset(Column<T> col, IndexOffset_t offset)
- -> cpp::result<T, ReadError> {
- return ReadDataAtOffset(col.Filename(), offset)
- .flat_map([&](cpp::span<std::byte> data) {
- auto res = = col.ParseValue(data);
- if (res) {
- return *res;
- } else {
- return cpp::fail(PARSE_ERROR);
- }
- });
- }
-
- private:
- auto ReadDataAtOffset(std::string filename, IndexOffset_t offset)
- -> cpp::span<std::byte>;
-};
-
-} // namespace database
diff --git a/src/database/include/table_writer.hpp b/src/database/include/table_writer.hpp
deleted file mode 100644
index 9e01dd9d..00000000
--- a/src/database/include/table_writer.hpp
+++ /dev/null
@@ -1,5 +0,0 @@
-#pragma once
-
-#include "table.hpp"
-
-namespace database {} // namespace database