From 3ac954922108b07fb3f7a7ce1c727bfcfad8b263 Mon Sep 17 00:00:00 2001
From: Ferenc Szontágh <szf@fsociety.hu>
Date: Thu, 27 Jun 2024 18:51:54 +0000
Subject: [PATCH] readme and some test
---
examples/example.cpp | 60 ++++++++++++++++++++
CMakeLists.txt | 2
README.md | 102 +++++++++++++++++++++++++++++++++
3 files changed, 161 insertions(+), 3 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 8c574b4..f67aa51 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,7 +25,7 @@
target_link_libraries(RocksDBWrapperExecutable RocksDBWrapper)
# Optionally add tests
-option(BUILD_TESTS "Build tests" ON)
+option(BUILD_TESTS "Build tests" OFF)
if (BUILD_TESTS)
include(FetchContent)
diff --git a/README.md b/README.md
index 378061c..430be0e 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,102 @@
-## RocksDBWrapper
+# RocksDBWrapper
-A simple wrapper for rocksdb
+RocksDBWrapper is a C++ library that provides a convenient interface for storing, retrieving, and indexing data using RocksDB. This library supports serialization of complex data structures and indexing for efficient queries.
+## Features
+
+* **Store and Retrieve Data:** Easily store and retrieve complex data structures.
+* **Key Existence Check:** Check if a specific key exists in the database.
+* **Member Indexing:** Index struct members for efficient search queries.
+* **Text Search:** Perform text-based searches on indexed members.
+* **Conditional Search:** Perform conditional searches on the data.
+
+## Installation
+
+### Dependencies
+
+* [RocksDB](https://github.com/facebook/rocksdb)
+* [tser](https://github.com/StefanoDacchille/tser)
+* [GoogleTest](https://github.com/google/googletest) (for testing)
+
+### Build
+
+```sh
+mkdir build
+cd build
+cmake .. -DBUILD_TESTS=ON # Add -DBUILD_TESTS=OFF if you do not want to build tests
+make
+```
+
+## Public Methods Documentation
+
+### Constructor and Destructor
+
+#### `RocksDBWrapper(const std::string &db_path, const std::string &index_path)`
+
+* **Description:** Constructs a `RocksDBWrapper` instance and opens the specified database and index paths.
+* **Parameters:**
+
+ * `db_path`: The path to the main RocksDB database.
+ * `index_path`: The path to the index RocksDB database.
+
+#### `~RocksDBWrapper()`
+
+* **Description:** Destructor that cleans up the database and index database resources.
+
+### Data Storage and Retrieval
+
+#### `template <typename T> void store(const std::string &key, const T &value)`
+
+* **Description:** Stores a value associated with the specified key.
+* **Parameters:**
+
+ * `key`: The key to associate with the value.
+ * `value`: The value to store.
+
+#### `template <typename T> bool get(const std::string &key, T &value)`
+
+* **Description:** Retrieves the value associated with the specified key.
+* **Parameters:**
+
+ * `key`: The key to retrieve the value for.
+ * `value`: The variable to store the retrieved value.
+* **Returns:** `true` if the key was found and the value was retrieved; `false` otherwise.
+
+### Key Existence
+
+#### `bool keyExists(const std::string &key)`
+
+* **Description:** Checks if a key exists in the database.
+* **Parameters:**
+
+ * `key`: The key to check for existence.
+* **Returns:** `true` if the key exists; `false` otherwise.
+
+### Searching
+
+#### `template <typename T> std::vector<std::string> search(const std::string &member_name, const std::string &member_value)`
+
+* **Description:** Searches for keys by a member's value.
+* **Parameters:**
+
+ * `member_name`: The name of the member to search by.
+ * `member_value`: The value of the member to search for.
+* **Returns:** A vector of keys that match the search criteria.
+
+#### `template <typename T> void search_text(const std::string &search_value, std::vector<T> &res)`
+
+* **Description:** Performs a text-based search on indexed members.
+* **Parameters:**
+
+ * `search_value`: The text to search for.
+ * `res`: A vector to store the results.
+
+#### `template <typename T> void search_conditional(std::vector<T> &res, std::function<bool(const T &)> condition)`
+
+* **Description:** Performs a conditional search on the data.
+* **Parameters:**
+
+ * `res`: A vector to store the results.
+ * `condition`: A function to define the search condition.
+
+This `README.md` provides a comprehensive overview of the `RocksDBWrapper` library, including installation instructions, usage examples, and documentation of public methods.
diff --git a/examples/example.cpp b/examples/example.cpp
new file mode 100644
index 0000000..f1c2dd3
--- /dev/null
+++ b/examples/example.cpp
@@ -0,0 +1,60 @@
+#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;
+}
\ No newline at end of file
--
Gitblit v1.9.3