Official C++ binding for TidesDB.
You must make sure you have the TidesDB shared C library installed on your system. Be sure to also compile with TIDESDB_WITH_SANITIZER and TIDESDB_BUILD_TESTS OFF.
cmake -S . -B build
cmake --build build
cmake --install build
#include <tidesdb.hpp>
int main() {
TidesDB::DB db;
db.Open("your_db_dir");
// Perform db operations...
db.Close();
return 0;
}
db.CreateColumnFamily("my_column_family", (1024*1024)*64, TDB_DEFAULT_SKIP_LIST_MAX_LEVEL, TDB_DEFAULT_SKIP_LIST_PROBABILITY, true, TIDESDB_COMPRESSION_LZ4, true, TIDESDB_MEMTABLE_SKIPLIST);
db.DropColumnFamily("my_column_family");
std::vector<uint8_t> key = {1, 2, 3};
std::vector<uint8_t> value = {4, 5, 6};
db.Put("my_column_family", &key, &value, -1);
std::vector<uint8_t> key = {1, 2, 3};
std::vector<uint8_t> value = {4, 5, 6};
db.Put("my_column_family", &key, &value, std::chrono::seconds(3600));
std::vector<uint8_t> retrieved_value;
db.Get("my_column_family", &key, &retrieved_value);
db.Delete("my_column_family", &key);
You can add operations to a transaction and commit them atomically.
TidesDB::Txn txn(&db);
txn.Begin();
txn.Put(&key, &value, std::chrono::seconds(3600));
txn.Commit();
You can iterate over the keys in a column family.
TidesDB::Cursor cursor(&db, "my_column_family");
cursor.Init();
std::vector<uint8_t> key, value;
cursor.Get(key, value);
cursor.Next(); // Go forwards
cursor.Prev(); // Go backwards
TidesDB::Cursor cursor(&db, "my_column_family");
cursor.Init();
std::vector<uint8_t> key, value;
while (cursor.Get(key, value) == 0) {
// Process key and value
cursor.Next();
}
You can manually trigger a compaction.
db.CompactSSTables("my_column_family", 4); // Use 4 threads for compaction
Or you can start partial background merge compactions.
db.StartBackgroundPartialMerges("my_column_family", std::chrono::seconds(60), 5); // Merge every 60 seconds if there are at least 5 SSTables