aboutsummaryrefslogtreecommitdiffstats
path: root/src/SqliteBackend.cpp
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-06-05 21:40:44 -0300
committerGitHub <noreply@github.com>2026-06-05 21:40:44 -0300
commit5174fc25698cff33b03b5746bf1742e417988f7d (patch)
tree232a3acdd9b458de481dbd5cbde889505168c8e8 /src/SqliteBackend.cpp
parent85ed897de3676af866cc619dc700025820c02201 (diff)
downloadRNT-5174fc25698cff33b03b5746bf1742e417988f7d.tar.gz
RNT-5174fc25698cff33b03b5746bf1742e417988f7d.zip
Project C interface, reroute FOL plan enums & format
Diffstat (limited to '')
-rw-r--r--src/SqliteBackend.cpp44
1 files changed, 16 insertions, 28 deletions
diff --git a/src/SqliteBackend.cpp b/src/SqliteBackend.cpp
index 7e9c9d5..3e01058 100644
--- a/src/SqliteBackend.cpp
+++ b/src/SqliteBackend.cpp
@@ -3,60 +3,48 @@
#include <picosha2.h>
#include <stdexcept>
-namespace nt
-{
- SqliteBackend::SqliteBackend(const std::string& path)
- {
+namespace nt {
+ SqliteBackend::SqliteBackend(const std::string& path) {
if (sqlite3_open(path.c_str(), &db_) != SQLITE_OK)
throw std::runtime_error(sqlite3_errmsg(db_));
- const char* schema =
- "CREATE TABLE IF NOT EXISTS kv ("
- " hash TEXT PRIMARY KEY,"
- " value BLOB NOT NULL"
- ");";
+ const char* schema = "CREATE TABLE IF NOT EXISTS kv ("
+ " hash TEXT PRIMARY KEY,"
+ " value BLOB NOT NULL"
+ ");";
char* err = nullptr;
- if (sqlite3_exec(db_, schema, nullptr, nullptr, &err) != SQLITE_OK)
- {
+ if (sqlite3_exec(db_, schema, nullptr, nullptr, &err) != SQLITE_OK) {
std::string msg(err);
sqlite3_free(err);
throw std::runtime_error(msg);
}
}
- SqliteBackend::~SqliteBackend()
- {
+ SqliteBackend::~SqliteBackend() {
sqlite3_close(db_);
}
- std::string SqliteBackend::Put(std::vector<uint8_t> value)
- {
+ std::string SqliteBackend::Put(std::vector<uint8_t> value) {
const std::string hash = picosha2::hash256_hex_string(value.begin(), value.end());
sqlite3_stmt* stmt = nullptr;
- sqlite3_prepare_v2(db_,
- "INSERT OR IGNORE INTO kv (hash, value) VALUES (?, ?)",
- -1, &stmt, nullptr);
+ sqlite3_prepare_v2(db_, "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;
}
- std::optional<std::vector<uint8_t>> SqliteBackend::Get(const std::string& hash)
- {
+ std::optional<std::vector<uint8_t>> SqliteBackend::Get(const std::string& hash) {
sqlite3_stmt* stmt = nullptr;
- sqlite3_prepare_v2(db_,
- "SELECT value FROM kv WHERE hash = ?",
- -1, &stmt, nullptr);
+ sqlite3_prepare_v2(db_, "SELECT value FROM kv WHERE hash = ?", -1, &stmt, nullptr);
sqlite3_bind_text(stmt, 1, hash.c_str(), -1, SQLITE_TRANSIENT);
std::optional<std::vector<uint8_t>> result;
- if (sqlite3_step(stmt) == SQLITE_ROW)
- {
+ if (sqlite3_step(stmt) == SQLITE_ROW) {
const auto* blob = static_cast<const uint8_t*>(sqlite3_column_blob(stmt, 0));
int size = sqlite3_column_bytes(stmt, 0);
result = std::vector<uint8_t>(blob, blob + size);
@@ -64,4 +52,4 @@ namespace nt
sqlite3_finalize(stmt);
return result;
}
-}
+} // namespace nt