This commit is contained in:
Your Name
2025-05-03 11:15:12 +12:00
parent a658ba1de6
commit 3c5fc11065
8 changed files with 82 additions and 18 deletions

View File

@@ -228,4 +228,22 @@ bool Database::list(std::vector<dbEntry>& entries) {
return true;
}
bool Database::update_or_insert(const dbEntry& entry) {
std::string sql = "INSERT OR REPLACE INTO objects (label_tag, hash, metadata) VALUES (?, ?, ?);";
sqlite3_stmt* stmt;
if (sqlite3_prepare_v2(db_, sql.c_str(), -1, &stmt, nullptr) != SQLITE_OK) {
return false;
}
sqlite3_bind_text(stmt, 1, entry.label_tag.c_str(), -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 2, entry.hash.c_str(), -1, SQLITE_STATIC);
std::string metadata_str = entry.metadata.dump();
sqlite3_bind_text(stmt, 3, metadata_str.c_str(), -1, SQLITE_STATIC);
bool success = sqlite3_step(stmt) == SQLITE_DONE;
sqlite3_finalize(stmt);
return success;
}
} // namespace simple_object_storage