summaryrefslogtreecommitdiff
path: root/src/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/database')
-rw-r--r--src/database/database.cpp28
-rw-r--r--src/database/include/database.hpp4
2 files changed, 32 insertions, 0 deletions
diff --git a/src/database/database.cpp b/src/database/database.cpp
index 27b5c24c..4bd9d2db 100644
--- a/src/database/database.cpp
+++ b/src/database/database.cpp
@@ -17,6 +17,7 @@
#include <memory>
#include <optional>
#include <sstream>
+#include <string>
#include <variant>
#include "collation.hpp"
@@ -198,6 +199,33 @@ Database::~Database() {
sIsDbOpen.store(false);
}
+auto Database::schemaVersion() -> std::string {
+ // If the database is open, then it must have the current schema.
+ return std::to_string(kCurrentDbVersion);
+}
+
+auto Database::sizeOnDiskBytes() -> size_t {
+ auto lock = drivers::acquire_spi();
+
+ FF_DIR dir;
+ FRESULT res = f_opendir(&dir, kDbPath);
+ if (res != FR_OK) {
+ return 0;
+ }
+
+ size_t total_size = 0;
+ for (;;) {
+ FILINFO info;
+ res = f_readdir(&dir, &info);
+ if (res != FR_OK || info.fname[0] == 0) {
+ break;
+ }
+ total_size += info.fsize;
+ }
+
+ return total_size;
+}
+
auto Database::put(const std::string& key, const std::string& val) -> void {
db_->Put(leveldb::WriteOptions{}, kKeyCustom + key, val);
}
diff --git a/src/database/include/database.hpp b/src/database/include/database.hpp
index 88a18e17..cb4064fb 100644
--- a/src/database/include/database.hpp
+++ b/src/database/include/database.hpp
@@ -63,6 +63,10 @@ class Database {
~Database();
+ auto schemaVersion() -> std::string;
+
+ auto sizeOnDiskBytes() -> size_t;
+
/* Adds an arbitrary record to the database. */
auto put(const std::string& key, const std::string& val) -> void;