@ohos-ports/lmdb 2.8.6-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +580 -0
  3. package/SECURITY.md +12 -0
  4. package/bin/download-prebuilds.js +15 -0
  5. package/binding.gyp +113 -0
  6. package/build/Release/lmdb.node +0 -0
  7. package/caching.js +212 -0
  8. package/dependencies/lmdb/libraries/liblmdb/COPYRIGHT +20 -0
  9. package/dependencies/lmdb/libraries/liblmdb/Doxyfile +1631 -0
  10. package/dependencies/lmdb/libraries/liblmdb/LICENSE +47 -0
  11. package/dependencies/lmdb/libraries/liblmdb/Makefile +136 -0
  12. package/dependencies/lmdb/libraries/liblmdb/chacha8.c +183 -0
  13. package/dependencies/lmdb/libraries/liblmdb/chacha8.h +14 -0
  14. package/dependencies/lmdb/libraries/liblmdb/crypto.c +121 -0
  15. package/dependencies/lmdb/libraries/liblmdb/intro.doc +192 -0
  16. package/dependencies/lmdb/libraries/liblmdb/lmdb.h +1817 -0
  17. package/dependencies/lmdb/libraries/liblmdb/mdb.c +12555 -0
  18. package/dependencies/lmdb/libraries/liblmdb/mdb_copy.1 +74 -0
  19. package/dependencies/lmdb/libraries/liblmdb/mdb_copy.c +106 -0
  20. package/dependencies/lmdb/libraries/liblmdb/mdb_drop.1 +53 -0
  21. package/dependencies/lmdb/libraries/liblmdb/mdb_drop.c +154 -0
  22. package/dependencies/lmdb/libraries/liblmdb/mdb_dump.1 +94 -0
  23. package/dependencies/lmdb/libraries/liblmdb/mdb_dump.c +333 -0
  24. package/dependencies/lmdb/libraries/liblmdb/mdb_load.1 +97 -0
  25. package/dependencies/lmdb/libraries/liblmdb/mdb_load.c +530 -0
  26. package/dependencies/lmdb/libraries/liblmdb/mdb_stat.1 +83 -0
  27. package/dependencies/lmdb/libraries/liblmdb/mdb_stat.c +276 -0
  28. package/dependencies/lmdb/libraries/liblmdb/midl-sparse.c +452 -0
  29. package/dependencies/lmdb/libraries/liblmdb/midl.c +452 -0
  30. package/dependencies/lmdb/libraries/liblmdb/midl.h +208 -0
  31. package/dependencies/lmdb/libraries/liblmdb/module.c +101 -0
  32. package/dependencies/lmdb/libraries/liblmdb/module.h +16 -0
  33. package/dependencies/lmdb/libraries/liblmdb/mtest.c +178 -0
  34. package/dependencies/lmdb/libraries/liblmdb/mtest2.c +124 -0
  35. package/dependencies/lmdb/libraries/liblmdb/mtest3.c +133 -0
  36. package/dependencies/lmdb/libraries/liblmdb/mtest4.c +168 -0
  37. package/dependencies/lmdb/libraries/liblmdb/mtest5.c +135 -0
  38. package/dependencies/lmdb/libraries/liblmdb/mtest6.c +141 -0
  39. package/dependencies/lmdb/libraries/liblmdb/mtest_enc.c +190 -0
  40. package/dependencies/lmdb/libraries/liblmdb/mtest_enc2.c +189 -0
  41. package/dependencies/lmdb/libraries/liblmdb/mtest_remap.c +177 -0
  42. package/dependencies/lmdb/libraries/liblmdb/sample-bdb.txt +73 -0
  43. package/dependencies/lmdb/libraries/liblmdb/sample-mdb.txt +62 -0
  44. package/dependencies/lmdb/libraries/liblmdb/tooltag +27 -0
  45. package/dependencies/lmdb-data-v1/libraries/liblmdb/CHANGES +266 -0
  46. package/dependencies/lmdb-data-v1/libraries/liblmdb/COPYRIGHT +20 -0
  47. package/dependencies/lmdb-data-v1/libraries/liblmdb/Doxyfile +1631 -0
  48. package/dependencies/lmdb-data-v1/libraries/liblmdb/LICENSE +47 -0
  49. package/dependencies/lmdb-data-v1/libraries/liblmdb/intro.doc +192 -0
  50. package/dependencies/lmdb-data-v1/libraries/liblmdb/lmdb.h +1608 -0
  51. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb.c +10320 -0
  52. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.1 +55 -0
  53. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_copy.c +82 -0
  54. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.1 +75 -0
  55. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_dump.c +319 -0
  56. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.1 +84 -0
  57. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_load.c +496 -0
  58. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.1 +64 -0
  59. package/dependencies/lmdb-data-v1/libraries/liblmdb/mdb_stat.c +263 -0
  60. package/dependencies/lmdb-data-v1/libraries/liblmdb/midl.c +359 -0
  61. package/dependencies/lmdb-data-v1/libraries/liblmdb/midl.h +186 -0
  62. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest.c +177 -0
  63. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest2.c +124 -0
  64. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest3.c +133 -0
  65. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest4.c +168 -0
  66. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest5.c +135 -0
  67. package/dependencies/lmdb-data-v1/libraries/liblmdb/mtest6.c +141 -0
  68. package/dependencies/lmdb-data-v1/libraries/liblmdb/sample-bdb.txt +73 -0
  69. package/dependencies/lmdb-data-v1/libraries/liblmdb/sample-mdb.txt +62 -0
  70. package/dependencies/lmdb-data-v1/libraries/liblmdb/tooltag +22 -0
  71. package/dependencies/lz4/LICENSE +11 -0
  72. package/dependencies/lz4/lib/LICENSE +24 -0
  73. package/dependencies/lz4/lib/Makefile +225 -0
  74. package/dependencies/lz4/lib/README.md +169 -0
  75. package/dependencies/lz4/lib/dll/example/Makefile +63 -0
  76. package/dependencies/lz4/lib/dll/example/README.md +69 -0
  77. package/dependencies/lz4/lib/dll/example/fullbench-dll.sln +25 -0
  78. package/dependencies/lz4/lib/dll/example/fullbench-dll.vcxproj +182 -0
  79. package/dependencies/lz4/lib/dll/liblz4.def +62 -0
  80. package/dependencies/lz4/lib/liblz4-dll.rc.in +35 -0
  81. package/dependencies/lz4/lib/liblz4.pc.in +14 -0
  82. package/dependencies/lz4/lib/lz4.c +2722 -0
  83. package/dependencies/lz4/lib/lz4.h +842 -0
  84. package/dependencies/lz4/lib/lz4file.c +311 -0
  85. package/dependencies/lz4/lib/lz4file.h +93 -0
  86. package/dependencies/lz4/lib/lz4frame.c +2078 -0
  87. package/dependencies/lz4/lib/lz4frame.h +692 -0
  88. package/dependencies/lz4/lib/lz4frame_static.h +47 -0
  89. package/dependencies/lz4/lib/lz4hc.c +1631 -0
  90. package/dependencies/lz4/lib/lz4hc.h +413 -0
  91. package/dependencies/lz4/lib/xxhash.c +1030 -0
  92. package/dependencies/lz4/lib/xxhash.h +328 -0
  93. package/dependencies/v8/v8-fast-api-calls-v16.h +791 -0
  94. package/dependencies/v8/v8-fast-api-calls.h +888 -0
  95. package/dict/dict.txt +1 -0
  96. package/dict/dict2.txt +1 -0
  97. package/dist/index.cjs +2950 -0
  98. package/dist/index.cjs.map +1 -0
  99. package/index.d.cts +420 -0
  100. package/index.d.ts +450 -0
  101. package/index.js +38 -0
  102. package/keys.js +116 -0
  103. package/level.js +27 -0
  104. package/native.js +85 -0
  105. package/node-index.js +32 -0
  106. package/open.js +448 -0
  107. package/package.json +124 -0
  108. package/read.js +833 -0
  109. package/rollup.config.js +12 -0
  110. package/src/compression.cpp +225 -0
  111. package/src/cursor.cpp +395 -0
  112. package/src/dbi.cpp +382 -0
  113. package/src/env.cpp +1030 -0
  114. package/src/lmdb-js.cpp +64 -0
  115. package/src/lmdb-js.h +633 -0
  116. package/src/misc.cpp +593 -0
  117. package/src/ordered-binary.cpp +46 -0
  118. package/src/txn.cpp +210 -0
  119. package/src/v8-functions.cpp +170 -0
  120. package/src/windows.c +35 -0
  121. package/src/writer.cpp +537 -0
  122. package/util/RangeIterable.js +236 -0
  123. package/util/set-optional-deps.cjs +14 -0
  124. package/util/when.js +8 -0
  125. package/write.js +912 -0
package/src/dbi.cpp ADDED
@@ -0,0 +1,382 @@
1
+ #include "lmdb-js.h"
2
+ #include <cstdio>
3
+
4
+ using namespace Napi;
5
+
6
+ void setFlagFromValue(int *flags, int flag, const char *name, bool defaultValue, Object options);
7
+
8
+ DbiWrap::DbiWrap(const Napi::CallbackInfo& info) : ObjectWrap<DbiWrap>(info) {
9
+ this->dbi = 0;
10
+ this->keyType = LmdbKeyType::DefaultKey;
11
+ this->compression = nullptr;
12
+ this->isOpen = false;
13
+ this->getFast = false;
14
+ this->ew = nullptr;
15
+ EnvWrap *ew;
16
+ napi_unwrap(info.Env(), info[0], (void**) &ew);
17
+ this->env = ew->env;
18
+ this->ew = ew;
19
+ int flags = info[1].As<Number>();
20
+ char* nameBytes;
21
+ std::string name;
22
+ if (info[2].IsString()) {
23
+ name = info[2].As<String>().Utf8Value();
24
+ nameBytes = (char*) name.c_str();
25
+ } else
26
+ nameBytes = nullptr;
27
+ LmdbKeyType keyType = (LmdbKeyType) info[3].As<Number>().Int32Value();
28
+ Compression* compression;
29
+ if (info[4].IsObject())
30
+ napi_unwrap(info.Env(), info[4], (void**) &compression);
31
+ else
32
+ compression = nullptr;
33
+ int rc = this->open(flags, nameBytes, flags & HAS_VERSIONS,
34
+ keyType, compression);
35
+ //if (nameBytes)
36
+ //delete nameBytes;
37
+ if (rc) {
38
+ if (rc == MDB_NOTFOUND)
39
+ this->dbi = (MDB_dbi) 0xffffffff;
40
+ else {
41
+ //delete this;
42
+ throwLmdbError(info.Env(), rc);
43
+ return;
44
+ }
45
+ }
46
+ info.This().As<Object>().Set("dbi", Number::New(info.Env(), this->dbi));
47
+ info.This().As<Object>().Set("address", Number::New(info.Env(), (size_t) this));
48
+ }
49
+
50
+
51
+ DbiWrap::~DbiWrap() {
52
+ // Imagine the following JS:
53
+ // ------------------------
54
+ // var dbi1 = env.openDbi({ name: "hello" });
55
+ // var dbi2 = env.openDbi({ name: "hello" });
56
+ // dbi1.close();
57
+ // txn.putString(dbi2, "world");
58
+ // -----
59
+ // The above DbiWrap objects would both wrap the same MDB_dbi, and if closing the first one called mdb_dbi_close,
60
+ // that'd also render the second DbiWrap instance unusable.
61
+ //
62
+ // For this reason, we will never call mdb_dbi_close
63
+ // NOTE: according to LMDB authors, it is perfectly fine if mdb_dbi_close is never called on an MDB_dbi
64
+ }
65
+
66
+
67
+ int DbiWrap::open(int flags, char* name, bool hasVersions, LmdbKeyType keyType, Compression* compression) {
68
+ MDB_txn* txn = ew->getReadTxn();
69
+ this->hasVersions = hasVersions;
70
+ this->compression = compression;
71
+ this->keyType = keyType;
72
+ #ifndef MDB_RPAGE_CACHE
73
+ flags &= ~0x100; // remove use versions flag for older lmdb
74
+ #endif
75
+ this->flags = flags;
76
+ int rc = txn ? mdb_dbi_open(txn, name, flags, &this->dbi) : EINVAL;
77
+ if (rc)
78
+ return rc;
79
+ this->isOpen = true;
80
+ if (keyType == LmdbKeyType::DefaultKey && name) { // use the fast compare, but can't do it if we have db table/names mixed in
81
+ mdb_set_compare(txn, dbi, compareFast);
82
+ }
83
+ return 0;
84
+ }
85
+
86
+ Value DbiWrap::close(const Napi::CallbackInfo& info) {
87
+ if (this->isOpen) {
88
+ mdb_dbi_close(this->env, this->dbi);
89
+ this->isOpen = false;
90
+ this->ew = nullptr;
91
+ }
92
+ else {
93
+ return throwError(info.Env(), "The Dbi is not open, you can't close it.");
94
+ }
95
+ return info.Env().Undefined();
96
+ }
97
+
98
+ Value DbiWrap::drop(const Napi::CallbackInfo& info) {
99
+ int del = 1;
100
+ int rc;
101
+ if (!this->isOpen) {
102
+ return throwError(info.Env(), "The Dbi is not open, you can't drop it.");
103
+ }
104
+
105
+ // Check if the database should be deleted
106
+ if (info.Length() == 1 && info[0].IsObject()) {
107
+ Napi::Object options = info[0].As<Object>();
108
+
109
+ // Just free pages
110
+ Napi::Value opt = options.Get("justFreePages");
111
+ del = opt.IsBoolean() ? !opt.As<Boolean>().Value() : 1;
112
+ }
113
+
114
+ // Drop database
115
+ rc = mdb_drop(ew->writeTxn->txn, dbi, del);
116
+ if (rc != 0) {
117
+ return throwLmdbError(info.Env(), rc);
118
+ }
119
+
120
+ // Only close database if del == 1
121
+ if (del == 1) {
122
+ isOpen = false;
123
+ ew = nullptr;
124
+ }
125
+ return info.Env().Undefined();
126
+ }
127
+
128
+ Value DbiWrap::stat(const Napi::CallbackInfo& info) {
129
+ MDB_stat stat;
130
+ mdb_stat(this->ew->getReadTxn(), dbi, &stat);
131
+ Object stats = Object::New(info.Env());
132
+ stats.Set("pageSize", Number::New(info.Env(), stat.ms_psize));
133
+ stats.Set("treeDepth", Number::New(info.Env(), stat.ms_depth));
134
+ stats.Set("treeBranchPageCount", Number::New(info.Env(), stat.ms_branch_pages));
135
+ stats.Set("treeLeafPageCount", Number::New(info.Env(), stat.ms_leaf_pages));
136
+ stats.Set("entryCount", Number::New(info.Env(), stat.ms_entries));
137
+ stats.Set("overflowPages", Number::New(info.Env(), stat.ms_overflow_pages));
138
+ return stats;
139
+ }
140
+
141
+ int32_t DbiWrap::doGetByBinary(uint32_t keySize, uint32_t ifNotTxnId, int64_t txnWrapAddress) {
142
+ char* keyBuffer = ew->keyBuffer;
143
+ MDB_txn* txn = ew->getReadTxn(txnWrapAddress);
144
+ MDB_val key, data;
145
+ key.mv_size = keySize;
146
+ key.mv_data = (void*) keyBuffer;
147
+ uint32_t* currentTxnId = (uint32_t*) (keyBuffer + 32);
148
+ #ifdef MDB_RPAGE_CACHE
149
+ int result = mdb_get_with_txn(txn, dbi, &key, &data, (mdb_size_t*) currentTxnId);
150
+ #else
151
+ int result = mdb_get(txn, dbi, &key, &data);
152
+ #endif
153
+ if (result) {
154
+ if (result > 0)
155
+ return -result;
156
+ return result;
157
+ }
158
+ #ifdef MDB_RPAGE_CACHE
159
+ if (ifNotTxnId && ifNotTxnId == *currentTxnId)
160
+ return -30004;
161
+ #endif
162
+ result = getVersionAndUncompress(data, this);
163
+ bool fits = true;
164
+ if (result) {
165
+ fits = valToBinaryFast(data, this); // it fits in the global/compression-target buffer
166
+ }
167
+ if (fits || result == 2 || data.mv_size < SHARED_BUFFER_THRESHOLD) {// result = 2 if it was decompressed
168
+ if (data.mv_size < 0x80000000)
169
+ return data.mv_size;
170
+ *((uint32_t*)keyBuffer) = data.mv_size;
171
+ return -30000;
172
+ } else {
173
+ return EnvWrap::toSharedBuffer(ew->env, (uint32_t*) ew->keyBuffer, data);
174
+ }
175
+ }
176
+
177
+ NAPI_FUNCTION(getByBinary) {
178
+ ARGS(4)
179
+ GET_INT64_ARG(0);
180
+ DbiWrap* dw = (DbiWrap*) i64;
181
+ uint32_t keySize;
182
+ GET_UINT32_ARG(keySize, 1);
183
+ uint32_t ifNotTxnId;
184
+ GET_UINT32_ARG(ifNotTxnId, 2);
185
+ int64_t txnAddress = 0;
186
+ napi_status status = napi_get_value_int64(env, args[3], &txnAddress);
187
+ RETURN_INT32(dw->doGetByBinary(keySize, ifNotTxnId, txnAddress));
188
+ }
189
+
190
+ uint32_t getByBinaryFFI(double dwPointer, uint32_t keySize, uint32_t ifNotTxnId, uint64_t txnAddress) {
191
+ DbiWrap* dw = (DbiWrap*) (size_t) dwPointer;
192
+ return dw->doGetByBinary(keySize, ifNotTxnId, txnAddress);
193
+ }
194
+
195
+ napi_finalize noopDbi = [](napi_env, void *, void *) {
196
+ // Data belongs to LMDB, we shouldn't free it here
197
+ };
198
+ NAPI_FUNCTION(getSharedByBinary) {
199
+ ARGS(2)
200
+ GET_INT64_ARG(0);
201
+ DbiWrap* dw = (DbiWrap*) i64;
202
+ uint32_t keySize;
203
+ GET_UINT32_ARG(keySize, 1);
204
+ MDB_val key;
205
+ MDB_val data;
206
+ key.mv_size = keySize;
207
+ key.mv_data = (void*) dw->ew->keyBuffer;
208
+ MDB_txn* txn = dw->ew->getReadTxn();
209
+ int rc = mdb_get(txn, dw->dbi, &key, &data);
210
+ if (rc) {
211
+ if (rc == MDB_NOTFOUND) {
212
+ RETURN_UNDEFINED;
213
+ } else
214
+ return throwLmdbError(env, rc);
215
+ }
216
+ rc = getVersionAndUncompress(data, dw);
217
+ napi_create_external_buffer(env, data.mv_size,
218
+ (char*) data.mv_data, noopDbi, nullptr, &returnValue);
219
+ return returnValue;
220
+ }
221
+ NAPI_FUNCTION(getStringByBinary) {
222
+ ARGS(3)
223
+ GET_INT64_ARG(0);
224
+ DbiWrap* dw = (DbiWrap*) i64;
225
+ uint32_t keySize;
226
+ GET_UINT32_ARG(keySize, 1);
227
+ int64_t txnAddress = 0;
228
+ napi_status status = napi_get_value_int64(env, args[2], &txnAddress);
229
+ MDB_val key;
230
+ MDB_val data;
231
+ key.mv_size = keySize;
232
+ key.mv_data = (void*) dw->ew->keyBuffer;
233
+ MDB_txn* txn = dw->ew->getReadTxn(txnAddress);
234
+ int rc = mdb_get(txn, dw->dbi, &key, &data);
235
+ if (rc) {
236
+ if (rc == MDB_NOTFOUND) {
237
+ RETURN_UNDEFINED;
238
+ } else
239
+ return throwLmdbError(env, rc);
240
+ }
241
+ rc = getVersionAndUncompress(data, dw);
242
+ if (rc)
243
+ napi_create_string_utf8(env, (char*) data.mv_data, data.mv_size, &returnValue);
244
+ else
245
+ napi_create_int32(env, data.mv_size, &returnValue);
246
+ return returnValue;
247
+ }
248
+
249
+ int DbiWrap::prefetch(uint32_t* keys) {
250
+ MDB_txn* txn;
251
+ mdb_txn_begin(ew->env, nullptr, MDB_RDONLY, &txn);
252
+ MDB_val key;
253
+ MDB_val data;
254
+ unsigned int flags;
255
+ mdb_dbi_flags(txn, dbi, &flags);
256
+ bool findAllValues = flags & MDB_DUPSORT;
257
+ int effected = 0;
258
+ bool findDataValue = false;
259
+ MDB_cursor *cursor;
260
+ int rc = mdb_cursor_open(txn, dbi, &cursor);
261
+ if (rc)
262
+ return rc;
263
+
264
+ while((key.mv_size = *keys++) > 0) {
265
+ if (key.mv_size == 0xffffffff) {
266
+ // it is a pointer to a new buffer
267
+ keys = (uint32_t*) (size_t) *((double*) keys); // read as a double pointer
268
+ key.mv_size = *keys++;
269
+ if (key.mv_size == 0)
270
+ break;
271
+ }
272
+ if (key.mv_size & 0x80000000) {
273
+ // indicator of using a data value combination (with dupSort), to be followed by the corresponding key
274
+ data.mv_size = key.mv_size & 0x7fffffff;
275
+ data.mv_data = (void *) keys;
276
+ keys += (data.mv_size + 12) >> 2;
277
+ findDataValue = true;
278
+ findAllValues = false;
279
+ continue;
280
+ }
281
+ // else standard key
282
+ key.mv_data = (void *) keys;
283
+ keys += (key.mv_size + 12) >> 2;
284
+ int rc = mdb_cursor_get(cursor, &key, &data, findDataValue ? MDB_GET_BOTH : MDB_SET_KEY);
285
+ findDataValue = false;
286
+ while (!rc) {
287
+ // access one byte from each of the pages to ensure they are in the OS cache,
288
+ // potentially triggering the hard page fault in this thread
289
+ int pages = (data.mv_size + 0xfff) >> 12;
290
+ // TODO: Adjust this for the page headers, I believe that makes the first page slightly less 4KB.
291
+ for (int i = 0; i < pages; i++) {
292
+ effected += *(((uint8_t*)data.mv_data) + (i << 12));
293
+ }
294
+ if (findAllValues) // in dupsort databases, access the rest of the values
295
+ rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT_DUP);
296
+ else
297
+ rc = 1; // done
298
+ }
299
+ }
300
+ mdb_cursor_close(cursor);
301
+ mdb_txn_abort(txn);
302
+ return effected;
303
+ }
304
+
305
+ class PrefetchWorker : public AsyncWorker {
306
+ public:
307
+ PrefetchWorker(DbiWrap* dw, uint32_t* keys, const Function& callback)
308
+ : AsyncWorker(callback), dw(dw), keys(keys) {}
309
+
310
+ void Execute() {
311
+ dw->prefetch(keys);
312
+ }
313
+
314
+ void OnOK() {
315
+ napi_value result; // we use direct napi call here because node-addon-api interface with throw a fatal error if a worker thread is terminating
316
+ napi_call_function(Env(), Env().Undefined(), Callback().Value(), 0, {}, &result);
317
+ }
318
+ void OnError(const Error& e) {
319
+ napi_value result; // we use direct napi call here because node-addon-api interface with throw a fatal error if a worker thread is terminating
320
+ napi_value arg = e.Value();
321
+ napi_call_function(Env(), Env().Undefined(), Callback().Value(), 1, &arg, &result);
322
+ }
323
+
324
+ private:
325
+ DbiWrap* dw;
326
+ uint32_t* keys;
327
+ };
328
+
329
+ NAPI_FUNCTION(prefetchNapi) {
330
+ ARGS(3)
331
+ GET_INT64_ARG(0);
332
+ DbiWrap* dw = (DbiWrap*) i64;
333
+ napi_get_value_int64(env, args[1], &i64);
334
+ uint32_t* keys = (uint32_t*) i64;
335
+ PrefetchWorker* worker = new PrefetchWorker(dw, keys, Function(env, args[2]));
336
+ worker->Queue();
337
+ RETURN_UNDEFINED;
338
+ }
339
+
340
+ void DbiWrap::setupExports(Napi::Env env, Object exports) {
341
+ Function DbiClass = DefineClass(env, "Dbi", {
342
+ // DbiWrap: Prepare constructor template
343
+ // DbiWrap: Add functions to the prototype
344
+ DbiWrap::InstanceMethod("close", &DbiWrap::close),
345
+ DbiWrap::InstanceMethod("drop", &DbiWrap::drop),
346
+ DbiWrap::InstanceMethod("stat", &DbiWrap::stat),
347
+ });
348
+ exports.Set("Dbi", DbiClass);
349
+ EXPORT_NAPI_FUNCTION("getByBinary", getByBinary);
350
+ EXPORT_NAPI_FUNCTION("prefetch", prefetchNapi);
351
+ EXPORT_NAPI_FUNCTION("getStringByBinary", getStringByBinary);
352
+ EXPORT_NAPI_FUNCTION("getSharedByBinary", getSharedByBinary);
353
+ EXPORT_FUNCTION_ADDRESS("getByBinaryPtr", getByBinaryFFI);
354
+ // TODO: wrap mdb_stat too
355
+ }
356
+
357
+
358
+
359
+
360
+ // This file contains code from the node-lmdb project
361
+ // Copyright (c) 2013-2017 Timur Kristóf
362
+ // Copyright (c) 2021 Kristopher Tate
363
+ // Licensed to you under the terms of the MIT license
364
+ //
365
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
366
+ // of this software and associated documentation files (the "Software"), to deal
367
+ // in the Software without restriction, including without limitation the rights
368
+ // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
369
+ // copies of the Software, and to permit persons to whom the Software is
370
+ // furnished to do so, subject to the following conditions:
371
+
372
+ // The above copyright notice and this permission notice shall be included in
373
+ // all copies or substantial portions of the Software.
374
+
375
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
376
+ // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
377
+ // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
378
+ // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
379
+ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
380
+ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
381
+ // THE SOFTWARE.
382
+