LeviLamina
Loading...
Searching...
No Matches
KeyValueDB.h
1#pragma once
2
3#include <filesystem>
4#include <functional>
5#include <memory>
6#include <optional>
7#include <string>
8#include <string_view>
9#include <vector>
10
11#include "ll/api/base/Macro.h"
12#include "ll/api/coro/Generator.h"
13
14namespace ll::data {
15class KeyValueDB {
16private:
17 class KeyValueDBImpl;
18
19 std::unique_ptr<KeyValueDBImpl> impl;
20
21public:
22 class WriteBatch {
23 friend class KeyValueDB;
24
25 class WriteBatchImpl;
26
27 std::unique_ptr<WriteBatchImpl> impl;
28
29 public:
30 LLNDAPI WriteBatch();
31
32 WriteBatch(WriteBatch const&) noexcept = delete;
33
34 WriteBatch& operator=(WriteBatch const&) noexcept = delete;
35
36 LLNDAPI WriteBatch(WriteBatch&&) noexcept;
37
38 LLAPI WriteBatch& operator=(WriteBatch&&) noexcept;
39
40 LLAPI ~WriteBatch();
41
42 LLAPI WriteBatch& set(std::string_view key, std::string_view val);
43
44 LLAPI WriteBatch& del(std::string_view key);
45 };
46
47 LLNDAPI explicit KeyValueDB(std::filesystem::path const& path);
48
49 LLNDAPI explicit KeyValueDB(
50 std::filesystem::path const& path,
51 bool createIfMiss,
52 bool fixIfError,
53 int bloomFilterBit
54 );
55
56 KeyValueDB(KeyValueDB const&) noexcept = delete;
57
58 KeyValueDB& operator=(KeyValueDB const&) noexcept = delete;
59
60 LLNDAPI KeyValueDB(KeyValueDB&&) noexcept;
61
62 LLAPI KeyValueDB& operator=(KeyValueDB&&) noexcept;
63
64 LLAPI ~KeyValueDB();
65
66 LLNDAPI std::optional<std::string> get(std::string_view key) const;
67
68 LLNDAPI bool has(std::string_view key) const;
69
70 LLNDAPI bool empty() const;
71
72 LLAPI bool set(std::string_view key, std::string_view val);
73
74 LLAPI bool del(std::string_view key);
75
76 LLAPI bool write(WriteBatch const& batch);
77
78 LLNDAPI coro::Generator<std::pair<std::string_view, std::string_view>> iter() const;
79};
80
81} // namespace ll::data
Definition KeyValueDB.h:22
STL namespace.