filename
This commit is contained in:
@@ -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
|
||||
|
Reference in New Issue
Block a user