aboutsummaryrefslogtreecommitdiffstats
path: root/src/SqliteBackend.cpp
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-05-13 01:59:22 -0300
committerGitHub <noreply@github.com>2026-05-13 01:59:22 -0300
commitaf6073dedffd1a16aff7a283ded50545dc40b179 (patch)
treea4b8fbfb4842f5ac27bf7fa641555de3fac6b7f3 /src/SqliteBackend.cpp
parentc1b70cfe745d935bded3053fba8c1f9573aa07aa (diff)
downloadRNT-af6073dedffd1a16aff7a283ded50545dc40b179.tar.gz
RNT-af6073dedffd1a16aff7a283ded50545dc40b179.zip
Extern handles for embedded runtime
Diffstat (limited to 'src/SqliteBackend.cpp')
-rw-r--r--src/SqliteBackend.cpp60
1 files changed, 2 insertions, 58 deletions
diff --git a/src/SqliteBackend.cpp b/src/SqliteBackend.cpp
index 4741033..7e9c9d5 100644
--- a/src/SqliteBackend.cpp
+++ b/src/SqliteBackend.cpp
@@ -1,18 +1,10 @@
#include "SqliteBackend.h"
#include <picosha2.h>
-#include <numeric>
#include <stdexcept>
namespace nt
{
- static std::string JoinPath(const std::vector<std::string>& path)
- {
- return std::accumulate(
- std::next(path.begin()), path.end(), path.front(),
- [](std::string a, const std::string& b) { return std::move(a) + "/" + b; });
- }
-
SqliteBackend::SqliteBackend(const std::string& path)
{
if (sqlite3_open(path.c_str(), &db_) != SQLITE_OK)
@@ -22,11 +14,6 @@ namespace nt
"CREATE TABLE IF NOT EXISTS kv ("
" hash TEXT PRIMARY KEY,"
" value BLOB NOT NULL"
- ");"
- "CREATE TABLE IF NOT EXISTS relation_index ("
- " path TEXT NOT NULL,"
- " tuple_hash TEXT NOT NULL,"
- " UNIQUE(path, tuple_hash)"
");";
char* err = nullptr;
@@ -43,11 +30,6 @@ namespace nt
sqlite3_close(db_);
}
- std::string SqliteBackend::PathKey(const std::vector<std::string>& path)
- {
- return JoinPath(path);
- }
-
std::string SqliteBackend::Put(std::vector<uint8_t> value)
{
const std::string hash = picosha2::hash256_hex_string(value.begin(), value.end());
@@ -57,10 +39,10 @@ namespace nt
"INSERT OR IGNORE INTO kv (hash, value) VALUES (?, ?)",
-1, &stmt, nullptr);
sqlite3_bind_text(stmt, 1, hash.c_str(), -1, SQLITE_TRANSIENT);
- sqlite3_bind_blob(stmt, 2, value.data(), static_cast<int>(value.size()), SQLITE_TRANSIENT);
+ sqlite3_bind_blob(stmt, 2, value.data(), static_cast<int>(value.size()),
+ SQLITE_TRANSIENT);
sqlite3_step(stmt);
sqlite3_finalize(stmt);
-
return hash;
}
@@ -82,42 +64,4 @@ namespace nt
sqlite3_finalize(stmt);
return result;
}
-
- void SqliteBackend::LinkTuple(const std::vector<std::string>& relation_path,
- const std::string& tuple_hash)
- {
- const std::string path_key = PathKey(relation_path);
-
- sqlite3_stmt* stmt = nullptr;
- sqlite3_prepare_v2(db_,
- "INSERT OR IGNORE INTO relation_index (path, tuple_hash) VALUES (?, ?)",
- -1, &stmt, nullptr);
- sqlite3_bind_text(stmt, 1, path_key.c_str(), -1, SQLITE_TRANSIENT);
- sqlite3_bind_text(stmt, 2, tuple_hash.c_str(), -1, SQLITE_TRANSIENT);
- sqlite3_step(stmt);
- sqlite3_finalize(stmt);
- }
-
- std::vector<std::string> SqliteBackend::TupleHashes(
- const std::vector<std::string>& relation_path,
- std::size_t offset,
- std::size_t limit)
- {
- const std::string path_key = PathKey(relation_path);
-
- sqlite3_stmt* stmt = nullptr;
- sqlite3_prepare_v2(db_,
- "SELECT tuple_hash FROM relation_index"
- " WHERE path = ? ORDER BY rowid LIMIT ? OFFSET ?",
- -1, &stmt, nullptr);
- sqlite3_bind_text(stmt, 1, path_key.c_str(), -1, SQLITE_TRANSIENT);
- sqlite3_bind_int64(stmt, 2, static_cast<sqlite3_int64>(limit));
- sqlite3_bind_int64(stmt, 3, static_cast<sqlite3_int64>(offset));
-
- std::vector<std::string> hashes;
- while (sqlite3_step(stmt) == SQLITE_ROW)
- hashes.emplace_back(reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0)));
- sqlite3_finalize(stmt);
- return hashes;
- }
}