#include "RocksDBWrapper.h"
|
#include "tser/tser.hpp"
|
#include <iostream>
|
#include <string>
|
|
struct TestStruct {
|
int id;
|
std::string name;
|
double value;
|
|
DEFINE_SERIALIZABLE(id, name, value);
|
};
|
|
int main() {
|
RocksDBWrapper db("/tmp/testdb", "/tmp/testindex");
|
|
TestStruct ts1{1, "Alpha", 1.1};
|
TestStruct ts2{2, "Beta", 2.2};
|
TestStruct ts3{3, "Gamma", 3.3};
|
|
// Store data
|
db.store("key1", ts1);
|
db.store("key2", ts2);
|
db.store("key3", ts3);
|
|
// Retrieve data
|
TestStruct retrieved;
|
if (db.get("key1", retrieved)) {
|
std::cout << "Retrieved: " << retrieved.name << std::endl;
|
}
|
|
// Check key existence
|
if (db.keyExists("key2")) {
|
std::cout << "Key 'key2' exists in the database." << std::endl;
|
}
|
|
// Search by member
|
auto keys = db.search<TestStruct>("name", "Beta");
|
for (const auto& key : keys) {
|
std::cout << "Found key for Beta: " << key << std::endl;
|
}
|
|
// Text search
|
std::vector<TestStruct> results;
|
db.search_text("Gam", results);
|
for (const auto& result : results) {
|
std::cout << "Text search found: " << result.name << std::endl;
|
}
|
|
// Conditional search
|
std::vector<TestStruct> cond_results;
|
db.search_conditional<TestStruct>(cond_results, [](const TestStruct& s) {
|
return s.value > 2.0;
|
});
|
for (const auto& result : cond_results) {
|
std::cout << "Conditional search found: " << result.name << std::endl;
|
}
|
|
return 0;
|
}
|