-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathnode_database.h
More file actions
62 lines (48 loc) · 1.7 KB
/
node_database.h
File metadata and controls
62 lines (48 loc) · 1.7 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once
#include <memory>
#include "main/lbug.h"
#include <napi.h>
using namespace lbug::main;
class NodeDatabase : public Napi::ObjectWrap<NodeDatabase> {
friend class NodeConnection;
friend class DatabaseInitAsyncWorker;
public:
static Napi::Object Init(Napi::Env env, Napi::Object exports);
explicit NodeDatabase(const Napi::CallbackInfo& info);
~NodeDatabase() override = default;
private:
Napi::Value InitAsync(const Napi::CallbackInfo& info);
Napi::Value InitSync(const Napi::CallbackInfo& info);
void InitCppDatabase();
void Close(const Napi::CallbackInfo& info);
static Napi::Value GetVersion(const Napi::CallbackInfo& info);
static Napi::Value GetStorageVersion(const Napi::CallbackInfo& info);
private:
std::string databasePath;
size_t bufferPoolSize;
bool enableCompression;
bool readOnly;
uint64_t maxDBSize;
bool autoCheckpoint;
int64_t checkpointThreshold;
bool throwOnWalReplayFailure;
bool enableChecksums;
std::shared_ptr<Database> database;
};
class DatabaseInitAsyncWorker : public Napi::AsyncWorker {
public:
DatabaseInitAsyncWorker(Napi::Function& callback, NodeDatabase* nodeDatabase)
: AsyncWorker(callback), nodeDatabase(nodeDatabase) {}
~DatabaseInitAsyncWorker() override = default;
inline void Execute() override {
try {
nodeDatabase->InitCppDatabase();
} catch (const std::exception& exc) {
SetError(std::string(exc.what()));
}
}
inline void OnOK() override { Callback().Call({Env().Null()}); }
inline void OnError(Napi::Error const& error) override { Callback().Call({error.Value()}); }
private:
NodeDatabase* nodeDatabase;
};