diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-01-15 12:31:20 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-01-15 12:31:20 +1100 |
| commit | 7cdcd44e0ca10ebdc796638190ed1d9b45d99ef0 (patch) | |
| tree | 637b43848d17c9dbdc1688cb4733eb235f223e37 /src/database | |
| parent | 0e04eb918ec976017276306181282769d8896c83 (diff) | |
| download | tangara-fw-7cdcd44e0ca10ebdc796638190ed1d9b45d99ef0.tar.gz | |
Begin migration of remaining screens to Lua
Diffstat (limited to 'src/database')
| -rw-r--r-- | src/database/database.cpp | 28 | ||||
| -rw-r--r-- | src/database/include/database.hpp | 4 |
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; |
