7#include <bits/chrono.h>
34 throw Napi::TypeError::New(
env,
"Directory needs to be a string");
43 throw Napi::TypeError::New(
env,
"Map size must be a number or an object");
53 throw Napi::TypeError::New(
env,
"The number of readers must be a number");
100 throw std::runtime_error(
format(
"LMDB store unavailable, was close already called?"));
106 _store->open_database(
req.db, !
req.uniqueKeys.value_or(
true));
123 for (
const auto&
entry :
req.entries) {
133 for (
const auto&
entry :
req.entries) {
138 if (
key_it == keys.end()) {
145 const auto& values =
vals[
static_cast<size_t>(
key_it - keys.begin())];
147 if (!values.has_value()) {
159 return std::find(values->begin(), values->end(), val) != values->begin();
169 bool reverse =
req.reverse.value_or(
false);
174 auto tx =
_store->create_shared_read_transaction();
187 start_ok = !cursor->read_prev(1, entries);
239 return { entries, done };
252 return { count, done };
259 batches.reserve(
req.batches.size());
261 for (
const auto&
data :
req.batches) {
263 batches.push_back(
batch);
266 auto start = std::chrono::high_resolution_clock::now();
268 auto end = std::chrono::high_resolution_clock::now();
269 std::chrono::duration<uint64_t, std::nano>
duration_ns = end - start;
302 _store->copy_store(
req.dstPath,
req.compact.value_or(
false));
bool count_until_next(const Key &key, uint64_t &count) const
bool read_next(uint64_t numKeysToRead, KeyDupValuesVector &keyValuePairs) const
bool read_prev(uint64_t numKeysToRead, KeyDupValuesVector &keyValuePairs) const
std::shared_ptr< LMDBCursor > SharedPtr
bool count_until_prev(const Key &key, uint64_t &count) const
void register_handler(uint32_t msgType, T *self, R(T::*handler)() const, bool unique=false)
Napi::Promise process_message(const Napi::CallbackInfo &info)
StartCursorResponse start_cursor(const StartCursorRequest &req)
GetResponse get(const GetRequest &req)
static Napi::Function get_class(Napi::Env env)
BoolResponse close_cursor(const CloseCursorRequest &req)
BoolResponse open_database(const OpenDatabaseRequest &req)
LMDBStoreWrapper(const Napi::CallbackInfo &)
bb::nodejs::AsyncMessageProcessor _msg_processor
HasResponse has(const HasRequest &req)
BatchResponse batch(const BatchRequest &req)
BoolResponse copy_store(const CopyStoreRequest &req)
void verify_store() const
std::unordered_map< uint64_t, CursorData > _cursors
StatsResponse get_stats()
static std::pair< bool, uint64_t > _advance_cursor_count(const lmdblib::LMDBCursor &cursor, bool reverse, const lmdblib::Key &end_key)
AdvanceCursorResponse advance_cursor(const AdvanceCursorRequest &req)
AdvanceCursorCountResponse advance_cursor_count(const AdvanceCursorCountRequest &req)
Napi::Value call(const Napi::CallbackInfo &)
The only instance method exposed to JavaScript. Takes a msgpack Message and returns a Promise.
static std::pair< bool, lmdblib::KeyDupValuesVector > _advance_cursor(const lmdblib::LMDBCursor &cursor, bool reverse, uint64_t page_size)
std::unique_ptr< lmdblib::LMDBStore > _store
std::string format(Args... args)
const std::vector< FF > data
const uint64_t DEFAULT_MAP_SIZE
const uint64_t DEFAULT_MAX_READERS
const uint64_t DEFAULT_CURSOR_PAGE_SIZE
std::vector< Key > KeysVector
std::vector< uint8_t > Key
std::vector< KeyValuesPair > KeyDupValuesVector
std::vector< OptionalValues > OptionalValuesVector
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept