Ferenc Szontágh
2024-06-27 3ac954922108b07fb3f7a7ce1c727bfcfad8b263
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <rocksdb/db.h>
#include <rocksdb/options.h>
#include <iostream>
#include <string>
#include <unordered_map>
#include <vector>
#include <regex>
#include "tser/tser.hpp"
#include "RocksDBWrapper.h"
 
// Define a sample struct with tser serialization
struct Book
{
    std::string title;
    int pages;
 
    // Define the members for serialization
    DEFINE_SERIALIZABLE(Book, title, pages)
};
 
int main()
{
    RocksDBWrapper db("testdb", "indexdb");
 
    // Create some sample books
    Book book1{"Book One", 30};
    Book book2{"Book Two", 15};
    Book book3{"Book Three", 50};
 
    // Store the books in the database
    db.store("book_1", book1);
    db.store("book_2", book2);
    db.store("book_3", book3);
 
    std::vector<Book> res;
    db.search_text("*One", res);
 
    for (const auto &_l : res)
    {
        std::cout << _l << std::endl;
    }
    
    Book _res;
    db.get("book_1", _res);
 
    std::cout << _res << std::endl;
}