From af6073dedffd1a16aff7a283ded50545dc40b179 Mon Sep 17 00:00:00 2001 From: Marcos Magueta Date: Wed, 13 May 2026 01:59:22 -0300 Subject: Extern handles for embedded runtime --- src/RelationalNT.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/RelationalNT.cpp') diff --git a/src/RelationalNT.cpp b/src/RelationalNT.cpp index e82b8c9..acf7ecb 100644 --- a/src/RelationalNT.cpp +++ b/src/RelationalNT.cpp @@ -5,6 +5,7 @@ #include "HandlerManager.h" #include "IdentityManager.h" #include "LifecycleManager.h" +#include "Merkle.h" #include "ObjectManager.h" #include "PermissionsManager.h" #include "SqliteBackend.h" @@ -40,15 +41,18 @@ int main() type->disposable = false; type->methods = { OPEN, CLOSE }; - objects.Register({ "multigroups", "sakura", "relations", "villager" }, std::make_unique(), std::move(type)); + const std::vector path = { "multigroups", "sakura", "relations", "villager" }; + objects.Register(path, std::make_unique(), std::move(type)); + auto* villager_rel = dynamic_cast( + objects.Find(path)->object.get()); - // --- Populate SQLite backend with three tuples --- + // --- Populate backend with three tuples via the Merkle tree --- nt::SqliteBackend backend; - const std::vector path = { "multigroups", "sakura", "relations", "villager" }; auto store = [&](std::vector attrs) { auto bytes = nt::TupleCodec::Serialize(attrs); - auto hash = backend.Put(bytes); - backend.LinkTuple(path, hash); + auto hash = backend.Put(std::move(bytes)); + villager_rel->merkle_root = + nt::Merkle::Insert(backend, villager_rel->merkle_root, hash); }; store({ { "name", "Blathers" }, { "profession", "Museum Curator" } }); store({ { "name", "Rover" }, { "profession", "Traveller" } }); @@ -62,7 +66,7 @@ int main() nt::HandlerManager handler(objects, permissions, identities, lifecycles); int connection = 1; // dummy connection context - nt::HandlerManager::handle* handle = handler.Open({ "multigroups", "sakura", "relations", "villager" }, &connection); + nt::HandlerManager::handle* handle = handler.Open(path, &connection); if (handle == nullptr) { std::cout << "Failed to open handle for villager\n"; @@ -70,7 +74,7 @@ int main() } // --- Open a cursor on the relation --- - nt::CursorManager::cursor* cursor = cursors.Open(handle); + nt::CursorManager::cursor* cursor = cursors.Open(handle, villager_rel->merkle_root); if (cursor == nullptr) { std::cout << "Failed to open cursor for villager\n"; -- cgit v1.2.3