Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# build instructions--
# cmake -S . -B build
# cmake --build build
# cmake --install build
cmake_minimum_required(VERSION 3.25)
project(tidesdb_cpp CXX)

Expand All @@ -8,13 +12,28 @@ add_compile_options(-Wextra -Wall -Werror)
find_library(LIBRARY_TIDEDB NAMES tidesdb REQUIRED) # require tidesdb library

add_library(tidesdb_cpp SHARED tidesdb.cpp)

install(FILES tidesdb.hpp
DESTINATION include)

if(APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
target_include_directories(tidesdb_cpp PUBLIC /opt/homebrew/include)
target_link_directories(tidesdb_cpp PUBLIC /opt/homebrew/lib)
elseif(APPLE)
target_include_directories(tidesdb_cpp PUBLIC /usr/local/include)
target_link_directories(tidesdb_cpp PUBLIC /usr/local/lib)
endif()

target_link_libraries(tidesdb_cpp PUBLIC ${LIBRARY_TIDEDB})

install(TARGETS tidesdb_cpp
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)

include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)

set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
Expand All @@ -26,4 +45,4 @@ add_executable(tests test/tests.cpp)
target_link_libraries(tests GTest::gtest_main tidesdb_cpp ${LIBRARY_TIDEDB})

include(GoogleTest)
gtest_discover_tests(tests)
gtest_discover_tests(tests)
101 changes: 100 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,103 @@
# tidesdb-cpp
Official C++ binding for TidesDB.

The C++ binding is in current active beta development. It is not recommended for production use.
## Getting Started
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.

### Build and install
```
cmake -S . -B build
cmake --build build
cmake --install build
```

### Create a TidesDB instance
```cpp
#include <tidesdb.hpp>

int main() {
TidesDB::DB db;
db.Open("your_db_dir");

// Perform db operations...

db.Close();
return 0;
}
```

### Creating and dropping column families
```cpp
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");
```

### CRUD operations
#### No TTL
```cpp
std::vector<uint8_t> key = {1, 2, 3};
std::vector<uint8_t> value = {4, 5, 6};
db.Put("my_column_family", &key, &value, -1);
```

#### With TTL
```cpp
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));
```

#### Get
```cpp
std::vector<uint8_t> retrieved_value;
db.Get("my_column_family", &key, &retrieved_value);
```

#### Deleting data
```cpp
db.Delete("my_column_family", &key);
```

## Transactions
You can add operations to a transaction and commit them atomically.
```cpp
TidesDB::Txn txn(&db);
txn.Begin();
txn.Put(&key, &value, std::chrono::seconds(3600));
txn.Commit();
```

## Cursor
You can iterate over the keys in a column family.
```cpp
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
```

```cpp
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();
}
```


## Compactions
You can manually trigger a compaction.
```cpp
db.CompactSSTables("my_column_family", 4); // Use 4 threads for compaction
```

Or you can start partial background merge compactions.
```cpp
db.StartBackgroundPartialMerges("my_column_family", std::chrono::seconds(60), 5); // Merge every 60 seconds if there are at least 5 SSTables
```
Loading