@nxtedition/rocksdb 11.0.8 → 11.1.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.
- package/binding.cc +70 -0
- package/index.js +2 -0
- package/iterator.js +6 -3
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/@nxtedition+rocksdb.node +0 -0
- package/prebuilds/linux-x64/@nxtedition+rocksdb.node +0 -0
- package/regex.js +21 -0
package/binding.cc
CHANGED
|
@@ -18,10 +18,12 @@
|
|
|
18
18
|
#include <rocksdb/table.h>
|
|
19
19
|
#include <rocksdb/write_batch.h>
|
|
20
20
|
|
|
21
|
+
|
|
21
22
|
#include <iostream>
|
|
22
23
|
#include <memory>
|
|
23
24
|
#include <optional>
|
|
24
25
|
#include <set>
|
|
26
|
+
#include <regex>
|
|
25
27
|
#include <string>
|
|
26
28
|
#include <thread>
|
|
27
29
|
#include <vector>
|
|
@@ -670,6 +672,7 @@ napi_status InitOptions(napi_env env, T& columnOptions, const U& options) {
|
|
|
670
672
|
columnOptions.compaction_style = rocksdb::kCompactionStyleUniversal;
|
|
671
673
|
columnOptions.compaction_options_universal.compression_size_percent = 80;
|
|
672
674
|
} else if (*compactionOpt == "level") {
|
|
675
|
+
columnOptions.write_buffer_size = static_cast<size_t>(memtable_memory_budget / 4);
|
|
673
676
|
// merge two memtables when flushing to L0
|
|
674
677
|
columnOptions.min_write_buffer_number_to_merge = 2;
|
|
675
678
|
// this means we'll use 50% extra memory in the worst case, but will reduce
|
|
@@ -1478,6 +1481,69 @@ NAPI_METHOD(batch_iterate) {
|
|
|
1478
1481
|
return result;
|
|
1479
1482
|
}
|
|
1480
1483
|
|
|
1484
|
+
NAPI_METHOD(regex_init) {
|
|
1485
|
+
NAPI_ARGV(1);
|
|
1486
|
+
|
|
1487
|
+
std::string pattern;
|
|
1488
|
+
NAPI_STATUS_THROWS(GetString(env, argv[0], pattern));
|
|
1489
|
+
|
|
1490
|
+
auto batch = std::make_unique<std::regex>(pattern);
|
|
1491
|
+
|
|
1492
|
+
napi_value result;
|
|
1493
|
+
NAPI_STATUS_THROWS(napi_create_external(env, batch.get(), Finalize<std::regex>, batch.get(), &result));
|
|
1494
|
+
batch.release();
|
|
1495
|
+
|
|
1496
|
+
return result;
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
NAPI_METHOD(regex_test) {
|
|
1500
|
+
NAPI_ARGV(2);
|
|
1501
|
+
|
|
1502
|
+
std::regex* regex;
|
|
1503
|
+
NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(®ex)));
|
|
1504
|
+
|
|
1505
|
+
rocksdb::Slice value;
|
|
1506
|
+
NAPI_STATUS_THROWS(GetValue(env, argv[1], value));
|
|
1507
|
+
|
|
1508
|
+
const bool match = std::regex_match(value.data(), value.data() + value.size(), *regex);
|
|
1509
|
+
|
|
1510
|
+
napi_value result;
|
|
1511
|
+
NAPI_STATUS_THROWS(napi_get_boolean(env, match, &result));
|
|
1512
|
+
|
|
1513
|
+
return result;
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
NAPI_METHOD(regex_test_many) {
|
|
1517
|
+
NAPI_ARGV(2);
|
|
1518
|
+
|
|
1519
|
+
std::regex* regex;
|
|
1520
|
+
NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(®ex)));
|
|
1521
|
+
|
|
1522
|
+
uint32_t count;
|
|
1523
|
+
NAPI_STATUS_THROWS(napi_get_array_length(env, argv[1], &count));
|
|
1524
|
+
|
|
1525
|
+
napi_value result;
|
|
1526
|
+
NAPI_STATUS_THROWS(napi_create_array_with_length(env, count, &result));
|
|
1527
|
+
|
|
1528
|
+
for (uint32_t n = 0; n < count; n++) {
|
|
1529
|
+
napi_value valueElement;
|
|
1530
|
+
NAPI_STATUS_THROWS(napi_get_element(env, argv[1], n, &valueElement));
|
|
1531
|
+
|
|
1532
|
+
rocksdb::Slice value;
|
|
1533
|
+
NAPI_STATUS_THROWS(GetValue(env, valueElement, value));
|
|
1534
|
+
|
|
1535
|
+
const bool match = std::regex_match(value.data(), value.data() + value.size(), *regex);
|
|
1536
|
+
|
|
1537
|
+
napi_value matchElement;
|
|
1538
|
+
NAPI_STATUS_THROWS(napi_get_boolean(env, match, &matchElement));
|
|
1539
|
+
|
|
1540
|
+
NAPI_STATUS_THROWS(napi_set_element(env, result, n, matchElement));
|
|
1541
|
+
}
|
|
1542
|
+
|
|
1543
|
+
return result;
|
|
1544
|
+
}
|
|
1545
|
+
|
|
1546
|
+
|
|
1481
1547
|
NAPI_INIT() {
|
|
1482
1548
|
NAPI_EXPORT_FUNCTION(db_init);
|
|
1483
1549
|
NAPI_EXPORT_FUNCTION(db_open);
|
|
@@ -1505,4 +1571,8 @@ NAPI_INIT() {
|
|
|
1505
1571
|
NAPI_EXPORT_FUNCTION(batch_merge);
|
|
1506
1572
|
NAPI_EXPORT_FUNCTION(batch_count);
|
|
1507
1573
|
NAPI_EXPORT_FUNCTION(batch_iterate);
|
|
1574
|
+
|
|
1575
|
+
NAPI_EXPORT_FUNCTION(regex_init);
|
|
1576
|
+
NAPI_EXPORT_FUNCTION(regex_test_many);
|
|
1577
|
+
NAPI_EXPORT_FUNCTION(regex_test);
|
|
1508
1578
|
}
|
package/index.js
CHANGED
|
@@ -5,6 +5,7 @@ const { AbstractLevel } = require('abstract-level')
|
|
|
5
5
|
const ModuleError = require('module-error')
|
|
6
6
|
const binding = require('./binding')
|
|
7
7
|
const { ChainedBatch } = require('./chained-batch')
|
|
8
|
+
const { Regex } = require('./regex')
|
|
8
9
|
const { Iterator } = require('./iterator')
|
|
9
10
|
const fs = require('node:fs')
|
|
10
11
|
const assert = require('node:assert')
|
|
@@ -264,3 +265,4 @@ class RocksLevel extends AbstractLevel {
|
|
|
264
265
|
}
|
|
265
266
|
|
|
266
267
|
exports.RocksLevel = RocksLevel
|
|
268
|
+
exports.Regex = Regex
|
package/iterator.js
CHANGED
|
@@ -107,16 +107,19 @@ class Iterator extends AbstractIterator {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
_close (callback) {
|
|
110
|
-
this[kCache] = kEmpty
|
|
111
|
-
|
|
112
110
|
try {
|
|
113
|
-
|
|
111
|
+
this._syncClose()
|
|
114
112
|
process.nextTick(callback)
|
|
115
113
|
} catch (err) {
|
|
116
114
|
process.nextTick(callback, err)
|
|
117
115
|
}
|
|
118
116
|
}
|
|
119
117
|
|
|
118
|
+
_syncClose () {
|
|
119
|
+
this[kCache] = kEmpty
|
|
120
|
+
binding.iterator_close(this[kContext])
|
|
121
|
+
}
|
|
122
|
+
|
|
120
123
|
_end (callback) {
|
|
121
124
|
this._close(callback)
|
|
122
125
|
}
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
package/regex.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const binding = require('./binding')
|
|
4
|
+
|
|
5
|
+
class Regex {
|
|
6
|
+
#context
|
|
7
|
+
|
|
8
|
+
constructor (pattern) {
|
|
9
|
+
this.#context = binding.regex_init(pattern)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
test (value) {
|
|
13
|
+
return binding.regex_test(this.#context, value)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
testMany (values) {
|
|
17
|
+
return binding.regex_test_many(this.#context, values)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
exports.Regex = Regex
|