@nxtedition/rocksdb 5.2.10 → 5.2.13

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 CHANGED
@@ -17,10 +17,8 @@
17
17
  namespace leveldb = rocksdb;
18
18
 
19
19
  #include <set>
20
- #include <optional>
21
20
  #include <memory>
22
21
  #include <string>
23
- #include <string_view>
24
22
  #include <vector>
25
23
 
26
24
  class NullLogger : public rocksdb::Logger {
@@ -64,7 +62,7 @@ static bool IsObject (napi_env env, napi_value value) {
64
62
  return type == napi_object;
65
63
  }
66
64
 
67
- static napi_value CreateError (napi_env env, const std::string_view& str) {
65
+ static napi_value CreateError (napi_env env, const std::string& str) {
68
66
  napi_value msg;
69
67
  napi_create_string_utf8(env, str.data(), str.size(), &msg);
70
68
  napi_value error;
@@ -72,7 +70,7 @@ static napi_value CreateError (napi_env env, const std::string_view& str) {
72
70
  return error;
73
71
  }
74
72
 
75
- static napi_value CreateCodeError (napi_env env, const std::string_view& code, const std::string_view& msg) {
73
+ static napi_value CreateCodeError (napi_env env, const std::string& code, const std::string& msg) {
76
74
  napi_value codeValue;
77
75
  napi_create_string_utf8(env, code.data(), code.size(), &codeValue);
78
76
  napi_value msgValue;
@@ -82,19 +80,19 @@ static napi_value CreateCodeError (napi_env env, const std::string_view& code, c
82
80
  return error;
83
81
  }
84
82
 
85
- static bool HasProperty (napi_env env, napi_value obj, const std::string_view& key) {
83
+ static bool HasProperty (napi_env env, napi_value obj, const std::string& key) {
86
84
  bool has = false;
87
85
  napi_has_named_property(env, obj, key.data(), &has);
88
86
  return has;
89
87
  }
90
88
 
91
- static napi_value GetProperty (napi_env env, napi_value obj, const std::string_view& key) {
89
+ static napi_value GetProperty (napi_env env, napi_value obj, const std::string& key) {
92
90
  napi_value value;
93
91
  napi_get_named_property(env, obj, key.data(), &value);
94
92
  return value;
95
93
  }
96
94
 
97
- static bool BooleanProperty (napi_env env, napi_value obj, const std::string_view& key,
95
+ static bool BooleanProperty (napi_env env, napi_value obj, const std::string& key,
98
96
  bool defaultValue) {
99
97
  if (HasProperty(env, obj, key.data())) {
100
98
  const auto value = GetProperty(env, obj, key.data());
@@ -106,12 +104,12 @@ static bool BooleanProperty (napi_env env, napi_value obj, const std::string_vie
106
104
  return defaultValue;
107
105
  }
108
106
 
109
- static bool EncodingIsBuffer (napi_env env, napi_value obj, const std::string_view& option) {
107
+ static bool EncodingIsBuffer (napi_env env, napi_value obj, const std::string& option) {
110
108
  napi_value value;
111
109
  size_t size;
112
110
 
113
111
  if (napi_get_named_property(env, obj, option.data(), &value) == napi_ok &&
114
- napi_get_value_string_utf8(env, value, NULL, 0, &size) == napi_ok) {
112
+ napi_get_value_string_utf8(env, value, nullptr, 0, &size) == napi_ok) {
115
113
  // Value is either "buffer" or "utf8" so we can tell them apart just by size
116
114
  return size == 6;
117
115
  }
@@ -119,7 +117,7 @@ static bool EncodingIsBuffer (napi_env env, napi_value obj, const std::string_vi
119
117
  return false;
120
118
  }
121
119
 
122
- static uint32_t Uint32Property (napi_env env, napi_value obj, const std::string_view& key,
120
+ static uint32_t Uint32Property (napi_env env, napi_value obj, const std::string& key,
123
121
  uint32_t defaultValue) {
124
122
  if (HasProperty(env, obj, key.data())) {
125
123
  const auto value = GetProperty(env, obj, key.data());
@@ -131,7 +129,7 @@ static uint32_t Uint32Property (napi_env env, napi_value obj, const std::string_
131
129
  return defaultValue;
132
130
  }
133
131
 
134
- static int Int32Property (napi_env env, napi_value obj, const std::string_view& key,
132
+ static int Int32Property (napi_env env, napi_value obj, const std::string& key,
135
133
  int defaultValue) {
136
134
  if (HasProperty(env, obj, key.data())) {
137
135
  const auto value = GetProperty(env, obj, key.data());
@@ -143,7 +141,7 @@ static int Int32Property (napi_env env, napi_value obj, const std::string_view&
143
141
  return defaultValue;
144
142
  }
145
143
 
146
- static std::optional<std::string> ToString (napi_env env, napi_value from) {
144
+ static std::string ToString (napi_env env, napi_value from, const std::string& defaultValue = "") {
147
145
  if (IsString(env, from)) {
148
146
  size_t length = 0;
149
147
  napi_get_value_string_utf8(env, from, nullptr, 0, &length);
@@ -157,14 +155,14 @@ static std::optional<std::string> ToString (napi_env env, napi_value from) {
157
155
  return std::string(buf, length);
158
156
  }
159
157
 
160
- return {};
158
+ return defaultValue;
161
159
  }
162
160
 
163
- static std::string StringProperty (napi_env env, napi_value obj, const std::string_view& key) {
161
+ static std::string StringProperty (napi_env env, napi_value obj, const std::string& key) {
164
162
  if (HasProperty(env, obj, key)) {
165
163
  napi_value value = GetProperty(env, obj, key);
166
164
  if (IsString(env, value)) {
167
- return ToString(env, value).value_or(std::string());
165
+ return ToString(env, value);
168
166
  }
169
167
  }
170
168
 
@@ -184,13 +182,13 @@ static size_t StringOrBufferLength (napi_env env, napi_value value) {
184
182
  return size;
185
183
  }
186
184
 
187
- static std::optional<std::string> RangeOption (napi_env env, napi_value opts, const std::string& name) {
185
+ static std::string* RangeOption (napi_env env, napi_value opts, const std::string& name) {
188
186
  if (HasProperty(env, opts, name)) {
189
187
  const auto value = GetProperty(env, opts, name);
190
- return ToString(env, value);
188
+ return new std::string(ToString(env, value));
191
189
  }
192
190
 
193
- return {};
191
+ return nullptr;
194
192
  }
195
193
 
196
194
  static std::vector<std::string> KeyArray (napi_env env, napi_value arr) {
@@ -205,7 +203,7 @@ static std::vector<std::string> KeyArray (napi_env env, napi_value arr) {
205
203
 
206
204
  if (napi_get_element(env, arr, i, &element) == napi_ok &&
207
205
  StringOrBufferLength(env, element) > 0) {
208
- result.push_back(ToString(env, element).value_or(std::string()));
206
+ result.push_back(ToString(env, element));
209
207
  }
210
208
  }
211
209
  }
@@ -222,17 +220,6 @@ static napi_status CallFunction (napi_env env,
222
220
  return napi_call_function(env, global, callback, argc, argv, nullptr);
223
221
  }
224
222
 
225
- template <typename T>
226
- void Convert (napi_env env, const std::optional<T>& s, bool asBuffer, napi_value& result) {
227
- if (!s) {
228
- napi_get_undefined(env, &result);
229
- } else if (asBuffer) {
230
- napi_create_buffer_copy(env, s->size(), s->data(), nullptr, &result);
231
- } else {
232
- napi_create_string_utf8(env, s->data(), s->size(), &result);
233
- }
234
- }
235
-
236
223
  template <typename T>
237
224
  void Convert (napi_env env, const T& s, bool asBuffer, napi_value& result) {
238
225
  if (asBuffer) {
@@ -407,6 +394,18 @@ struct Database {
407
394
  return db_->Write(options, batch);
408
395
  }
409
396
 
397
+ uint64_t ApproximateSize (const leveldb::Range* range) {
398
+ uint64_t size = 0;
399
+ db_->GetApproximateSizes(range, 1, &size);
400
+ return size;
401
+ }
402
+
403
+ void CompactRange (const leveldb::Slice* start,
404
+ const leveldb::Slice* end) {
405
+ rocksdb::CompactRangeOptions options;
406
+ db_->CompactRange(options, start, end);
407
+ }
408
+
410
409
  void GetProperty (const std::string& property, std::string& value) {
411
410
  db_->GetProperty(property, &value);
412
411
  }
@@ -479,10 +478,10 @@ struct PriorityWorker : public BaseWorker {
479
478
  struct BaseIterator {
480
479
  BaseIterator(Database* database,
481
480
  const bool reverse,
482
- const std::optional<std::string>& lt,
483
- const std::optional<std::string>& lte,
484
- const std::optional<std::string>& gt,
485
- const std::optional<std::string>& gte,
481
+ const std::string* lt,
482
+ const std::string* lte,
483
+ const std::string* gt,
484
+ const std::string* gte,
486
485
  const int limit,
487
486
  const bool fillCache)
488
487
  : database_(database),
@@ -506,6 +505,11 @@ struct BaseIterator {
506
505
 
507
506
  virtual ~BaseIterator () {
508
507
  assert(!dbIterator_);
508
+
509
+ delete lt_;
510
+ delete lte_;
511
+ delete gt_;
512
+ delete gte_;
509
513
  }
510
514
 
511
515
  bool DidSeek () const {
@@ -648,10 +652,10 @@ private:
648
652
  leveldb::Iterator* dbIterator_;
649
653
  bool didSeek_;
650
654
  const bool reverse_;
651
- const std::optional<std::string> lt_;
652
- const std::optional<std::string> lte_;
653
- const std::optional<std::string> gt_;
654
- const std::optional<std::string> gte_;
655
+ const std::string* lt_;
656
+ const std::string* lte_;
657
+ const std::string* gt_;
658
+ const std::string* gte_;
655
659
  const int limit_;
656
660
  int count_;
657
661
  };
@@ -662,10 +666,10 @@ struct Iterator final : public BaseIterator {
662
666
  const bool keys,
663
667
  const bool values,
664
668
  const int limit,
665
- const std::optional<std::string>& lt,
666
- const std::optional<std::string>& lte,
667
- const std::optional<std::string>& gt,
668
- const std::optional<std::string>& gte,
669
+ const std::string* lt,
670
+ const std::string* lte,
671
+ const std::string* gt,
672
+ const std::string* gte,
669
673
  const bool fillCache,
670
674
  const bool keyAsBuffer,
671
675
  const bool valueAsBuffer,
@@ -876,7 +880,7 @@ NAPI_METHOD(db_open) {
876
880
  NAPI_ARGV(4);
877
881
  NAPI_DB_CONTEXT();
878
882
 
879
- const auto location = ToString(env, argv[1]).value_or(std::string());
883
+ const auto location = ToString(env, argv[1]);
880
884
  const auto options = argv[2];
881
885
  const auto createIfMissing = BooleanProperty(env, options, "createIfMissing", true);
882
886
  const auto errorIfExists = BooleanProperty(env, options, "errorIfExists", false);
@@ -952,7 +956,7 @@ struct PutWorker final : public PriorityWorker {
952
956
  const std::string& key,
953
957
  const std::string& value,
954
958
  bool sync)
955
- : PriorityWorker(env, database, callback, "classic_level.db.put"),
959
+ : PriorityWorker(env, database, callback, "rocks_level.db.put"),
956
960
  key_(key), value_(value), sync_(sync) {
957
961
  }
958
962
 
@@ -971,8 +975,8 @@ NAPI_METHOD(db_put) {
971
975
  NAPI_ARGV(5);
972
976
  NAPI_DB_CONTEXT();
973
977
 
974
- const auto key = ToString(env, argv[1]).value_or(std::string());
975
- const auto value = ToString(env, argv[2]).value_or(std::string());
978
+ const auto key = ToString(env, argv[1]);
979
+ const auto value = ToString(env, argv[2]);
976
980
  const auto sync = BooleanProperty(env, argv[3], "sync", false);
977
981
  const auto callback = argv[4];
978
982
 
@@ -989,7 +993,7 @@ struct GetWorker final : public PriorityWorker {
989
993
  const std::string& key,
990
994
  const bool asBuffer,
991
995
  const bool fillCache)
992
- : PriorityWorker(env, database, callback, "classic_level.db.get"),
996
+ : PriorityWorker(env, database, callback, "rocks_level.db.get"),
993
997
  key_(key), asBuffer_(asBuffer), fillCache_(fillCache) {
994
998
  }
995
999
 
@@ -1017,7 +1021,7 @@ NAPI_METHOD(db_get) {
1017
1021
  NAPI_ARGV(4);
1018
1022
  NAPI_DB_CONTEXT();
1019
1023
 
1020
- const auto key = ToString(env, argv[1]).value_or(std::string());
1024
+ const auto key = ToString(env, argv[1]);
1021
1025
  const auto options = argv[2];
1022
1026
  const auto asBuffer = EncodingIsBuffer(env, options, "valueEncoding");
1023
1027
  const auto fillCache = BooleanProperty(env, options, "fillCache", true);
@@ -1029,7 +1033,6 @@ NAPI_METHOD(db_get) {
1029
1033
  return 0;
1030
1034
  }
1031
1035
 
1032
-
1033
1036
  struct GetManyWorker final : public PriorityWorker {
1034
1037
  GetManyWorker (napi_env env,
1035
1038
  Database* database,
@@ -1062,9 +1065,9 @@ struct GetManyWorker final : public PriorityWorker {
1062
1065
  const auto status = database_->Get(options, key, value);
1063
1066
 
1064
1067
  if (status.ok()) {
1065
- cache_.push_back(std::move(value));
1068
+ cache_.emplace_back(std::move(value));
1066
1069
  } else if (status.IsNotFound()) {
1067
- cache_.push_back({});
1070
+ cache_.emplace_back(nullptr);
1068
1071
  } else {
1069
1072
  SetStatus(status);
1070
1073
  break;
@@ -1085,7 +1088,11 @@ struct GetManyWorker final : public PriorityWorker {
1085
1088
 
1086
1089
  for (size_t idx = 0; idx < size; idx++) {
1087
1090
  napi_value element;
1088
- Convert(env, cache_[idx], valueAsBuffer_, element);
1091
+ if (cache_[idx].GetSelf() != nullptr) {
1092
+ Convert(env, cache_[idx], valueAsBuffer_, element);
1093
+ } else {
1094
+ napi_get_undefined(env, &element);
1095
+ }
1089
1096
  napi_set_element(env, array, static_cast<uint32_t>(idx), element);
1090
1097
  }
1091
1098
 
@@ -1098,7 +1105,7 @@ struct GetManyWorker final : public PriorityWorker {
1098
1105
  private:
1099
1106
  const std::vector<std::string> keys_;
1100
1107
  const bool valueAsBuffer_;
1101
- std::vector<std::optional<rocksdb::PinnableSlice>> cache_;
1108
+ std::vector<rocksdb::PinnableSlice> cache_;
1102
1109
  const bool fillCache_;
1103
1110
  const leveldb::Snapshot* snapshot_;
1104
1111
  };
@@ -1125,7 +1132,7 @@ struct DelWorker final : public PriorityWorker {
1125
1132
  napi_value callback,
1126
1133
  const std::string& key,
1127
1134
  bool sync)
1128
- : PriorityWorker(env, database, callback, "classic_level.db.del"),
1135
+ : PriorityWorker(env, database, callback, "rocks_level.db.del"),
1129
1136
  key_(key), sync_(sync) {
1130
1137
  }
1131
1138
 
@@ -1143,7 +1150,7 @@ NAPI_METHOD(db_del) {
1143
1150
  NAPI_ARGV(4);
1144
1151
  NAPI_DB_CONTEXT();
1145
1152
 
1146
- const auto key = ToString(env, argv[1]).value_or(std::string());
1153
+ const auto key = ToString(env, argv[1]);
1147
1154
  const auto sync = BooleanProperty(env, argv[2], "sync", false);
1148
1155
  const auto callback = argv[3];
1149
1156
 
@@ -1159,11 +1166,11 @@ struct ClearWorker final : public PriorityWorker {
1159
1166
  napi_value callback,
1160
1167
  const bool reverse,
1161
1168
  const int limit,
1162
- const std::optional<std::string>& lt,
1163
- const std::optional<std::string>& lte,
1164
- const std::optional<std::string>& gt,
1165
- const std::optional<std::string>& gte)
1166
- : PriorityWorker(env, database, callback, "classic_level.db.clear"),
1169
+ const std::string* lt,
1170
+ const std::string* lte,
1171
+ const std::string* gt,
1172
+ const std::string* gte)
1173
+ : PriorityWorker(env, database, callback, "rocks_level.db.clear"),
1167
1174
  iterator_(database, reverse, lt, lte, gt, gte, limit, false) {
1168
1175
  }
1169
1176
 
@@ -1226,6 +1233,150 @@ NAPI_METHOD(db_clear) {
1226
1233
  return 0;
1227
1234
  }
1228
1235
 
1236
+ struct ApproximateSizeWorker final : public PriorityWorker {
1237
+ ApproximateSizeWorker (napi_env env,
1238
+ Database* database,
1239
+ napi_value callback,
1240
+ const std::string& start,
1241
+ const std::string& end)
1242
+ : PriorityWorker(env, database, callback, "rocks_level.db.approximate_size"),
1243
+ start_(start), end_(end) {}
1244
+
1245
+ void DoExecute () override {
1246
+ leveldb::Range range(start_, end_);
1247
+ size_ = database_->ApproximateSize(&range);
1248
+ }
1249
+
1250
+ void HandleOKCallback (napi_env env, napi_value callback) override {
1251
+ napi_value argv[2];
1252
+ napi_get_null(env, &argv[0]);
1253
+ napi_create_int64(env, size_, &argv[1]);
1254
+ CallFunction(env, callback, 2, argv);
1255
+ }
1256
+
1257
+ std::string start_;
1258
+ std::string end_;
1259
+ uint64_t size_;
1260
+ };
1261
+
1262
+ NAPI_METHOD(db_approximate_size) {
1263
+ NAPI_ARGV(4);
1264
+ NAPI_DB_CONTEXT();
1265
+
1266
+ const auto start = ToString(env, argv[1]);
1267
+ const auto end = ToString(env, argv[2]);
1268
+ const auto callback = argv[3];
1269
+
1270
+ auto worker = new ApproximateSizeWorker(env, database, callback, start, end);
1271
+ worker->Queue(env);
1272
+
1273
+ return 0;
1274
+ }
1275
+
1276
+ struct CompactRangeWorker final : public PriorityWorker {
1277
+ CompactRangeWorker (napi_env env,
1278
+ Database* database,
1279
+ napi_value callback,
1280
+ const std::string& start,
1281
+ const std::string& end)
1282
+ : PriorityWorker(env, database, callback, "rocks_level.db.compact_range"),
1283
+ start_(start), end_(end) {}
1284
+
1285
+ void DoExecute () override {
1286
+ leveldb::Slice start = start_;
1287
+ leveldb::Slice end = end_;
1288
+ database_->CompactRange(&start, &end);
1289
+ }
1290
+
1291
+ const std::string start_;
1292
+ const std::string end_;
1293
+ };
1294
+
1295
+ NAPI_METHOD(db_compact_range) {
1296
+ NAPI_ARGV(4);
1297
+ NAPI_DB_CONTEXT();
1298
+
1299
+ const auto start = ToString(env, argv[1]);
1300
+ const auto end = ToString(env, argv[2]);
1301
+ const auto callback = argv[3];
1302
+
1303
+ auto worker = new CompactRangeWorker(env, database, callback, start, end);
1304
+ worker->Queue(env);
1305
+
1306
+ return 0;
1307
+ }
1308
+
1309
+ NAPI_METHOD(db_get_property) {
1310
+ NAPI_ARGV(2);
1311
+ NAPI_DB_CONTEXT();
1312
+
1313
+ const auto property = ToString(env, argv[1]);
1314
+
1315
+ std::string value;
1316
+ database->GetProperty(property, value);
1317
+
1318
+ napi_value result;
1319
+ napi_create_string_utf8(env, value.data(), value.size(), &result);
1320
+
1321
+ return result;
1322
+ }
1323
+
1324
+ struct DestroyWorker final : public BaseWorker {
1325
+ DestroyWorker (napi_env env,
1326
+ const std::string& location,
1327
+ napi_value callback)
1328
+ : BaseWorker(env, nullptr, callback, "rocks_level.destroy_db"),
1329
+ location_(location) {}
1330
+
1331
+ ~DestroyWorker () {}
1332
+
1333
+ void DoExecute () override {
1334
+ leveldb::Options options;
1335
+ SetStatus(leveldb::DestroyDB(location_, options));
1336
+ }
1337
+
1338
+ const std::string location_;
1339
+ };
1340
+
1341
+ NAPI_METHOD(destroy_db) {
1342
+ NAPI_ARGV(2);
1343
+
1344
+ const auto location = ToString(env, argv[0]);
1345
+ const auto callback = argv[1];
1346
+
1347
+ auto worker = new DestroyWorker(env, location, callback);
1348
+ worker->Queue(env);
1349
+
1350
+ return 0;
1351
+ }
1352
+
1353
+ struct RepairWorker final : public BaseWorker {
1354
+ RepairWorker (napi_env env,
1355
+ const std::string& location,
1356
+ napi_value callback)
1357
+ : BaseWorker(env, nullptr, callback, "rocks_level.repair_db"),
1358
+ location_(location) {}
1359
+
1360
+ void DoExecute () override {
1361
+ leveldb::Options options;
1362
+ SetStatus(leveldb::RepairDB(location_, options));
1363
+ }
1364
+
1365
+ const std::string location_;
1366
+ };
1367
+
1368
+ NAPI_METHOD(repair_db) {
1369
+ NAPI_ARGV(2);
1370
+
1371
+ const auto location = ToString(env, argv[1]);
1372
+ const auto callback = argv[1];
1373
+
1374
+ auto worker = new RepairWorker(env, location, callback);
1375
+ worker->Queue(env);
1376
+
1377
+ return 0;
1378
+ }
1379
+
1229
1380
  static void FinalizeIterator (napi_env env, void* data, void* hint) {
1230
1381
  if (data) {
1231
1382
  delete reinterpret_cast<Iterator*>(data);
@@ -1275,7 +1426,7 @@ NAPI_METHOD(iterator_seek) {
1275
1426
  napi_throw_error(env, nullptr, "iterator has closed");
1276
1427
  }
1277
1428
 
1278
- const auto target = ToString(env, argv[1]).value_or(std::string());
1429
+ const auto target = ToString(env, argv[1]);
1279
1430
  iterator->first_ = true;
1280
1431
  iterator->Seek(target);
1281
1432
 
@@ -1427,7 +1578,7 @@ struct BatchWorker final : public PriorityWorker {
1427
1578
  leveldb::WriteBatch* batch,
1428
1579
  const bool sync,
1429
1580
  const bool hasData)
1430
- : PriorityWorker(env, database, callback, "classic_level.batch.do"),
1581
+ : PriorityWorker(env, database, callback, "rocks_level.batch.do"),
1431
1582
  batch_(batch), hasData_(hasData) {
1432
1583
  options_.sync = sync;
1433
1584
  }
@@ -1472,7 +1623,7 @@ NAPI_METHOD(batch_do) {
1472
1623
 
1473
1624
  if (type == "del") {
1474
1625
  if (!HasProperty(env, element, "key")) continue;
1475
- const auto key = ToString(env, GetProperty(env, element, "key")).value_or(std::string());
1626
+ const auto key = ToString(env, GetProperty(env, element, "key"));
1476
1627
 
1477
1628
  batch->Delete(key);
1478
1629
  if (!hasData) hasData = true;
@@ -1480,8 +1631,8 @@ NAPI_METHOD(batch_do) {
1480
1631
  if (!HasProperty(env, element, "key")) continue;
1481
1632
  if (!HasProperty(env, element, "value")) continue;
1482
1633
 
1483
- const auto key = ToString(env, GetProperty(env, element, "key")).value_or(std::string());
1484
- const auto value = ToString(env, GetProperty(env, element, "value")).value_or(std::string());
1634
+ const auto key = ToString(env, GetProperty(env, element, "key"));
1635
+ const auto value = ToString(env, GetProperty(env, element, "value"));
1485
1636
 
1486
1637
  batch->Put(key, value);
1487
1638
  if (!hasData) hasData = true;
@@ -1517,8 +1668,8 @@ NAPI_METHOD(batch_put) {
1517
1668
  NAPI_ARGV(3);
1518
1669
  NAPI_BATCH_CONTEXT();
1519
1670
 
1520
- const auto key = ToString(env, argv[1]).value_or(std::string());
1521
- const auto value = ToString(env, argv[2]).value_or(std::string());
1671
+ const auto key = ToString(env, argv[1]);
1672
+ const auto value = ToString(env, argv[2]);
1522
1673
 
1523
1674
  batch->Put(key, value);
1524
1675
 
@@ -1529,7 +1680,7 @@ NAPI_METHOD(batch_del) {
1529
1680
  NAPI_ARGV(2);
1530
1681
  NAPI_BATCH_CONTEXT();
1531
1682
 
1532
- const auto key = ToString(env, argv[1]).value_or(std::string());
1683
+ const auto key = ToString(env, argv[1]);
1533
1684
 
1534
1685
  batch->Delete(key);
1535
1686
 
@@ -1601,6 +1752,12 @@ NAPI_INIT() {
1601
1752
  NAPI_EXPORT_FUNCTION(db_get_many);
1602
1753
  NAPI_EXPORT_FUNCTION(db_del);
1603
1754
  NAPI_EXPORT_FUNCTION(db_clear);
1755
+ NAPI_EXPORT_FUNCTION(db_approximate_size);
1756
+ NAPI_EXPORT_FUNCTION(db_compact_range);
1757
+ NAPI_EXPORT_FUNCTION(db_get_property);
1758
+
1759
+ NAPI_EXPORT_FUNCTION(destroy_db);
1760
+ NAPI_EXPORT_FUNCTION(repair_db);
1604
1761
 
1605
1762
  NAPI_EXPORT_FUNCTION(iterator_init);
1606
1763
  NAPI_EXPORT_FUNCTION(iterator_seek);
package/binding.gyp CHANGED
@@ -23,7 +23,7 @@
23
23
  }
24
24
  }
25
25
  }, { # OS != 'win'
26
- 'cflags': [ '-std=c++20' ]
26
+ 'cflags': [ '-std=c++17' ]
27
27
  , 'cflags!': [ '-fno-rtti' ]
28
28
  , 'cflags_cc!': [ '-fno-rtti' ]
29
29
  , 'cflags_cc+': [ '-frtti' ]
@@ -40,7 +40,7 @@
40
40
  ]
41
41
  , 'OTHER_CPLUSPLUSFLAGS': [
42
42
  '-mmacosx-version-min=10.14'
43
- , '-std=c++20'
43
+ , '-std=c++17'
44
44
  , '-stdlib=libc++'
45
45
  , '-arch x86_64'
46
46
  , '-arch arm64'
@@ -0,0 +1,32 @@
1
+ ## RocksDB: A Persistent Key-Value Store for Flash and RAM Storage
2
+
3
+ [![CircleCI Status](https://circleci.com/gh/facebook/rocksdb.svg?style=svg)](https://circleci.com/gh/facebook/rocksdb)
4
+ [![TravisCI Status](https://travis-ci.org/facebook/rocksdb.svg?branch=master)](https://travis-ci.org/facebook/rocksdb)
5
+ [![Appveyor Build status](https://ci.appveyor.com/api/projects/status/fbgfu0so3afcno78/branch/master?svg=true)](https://ci.appveyor.com/project/Facebook/rocksdb/branch/master)
6
+ [![PPC64le Build Status](http://140-211-168-68-openstack.osuosl.org:8080/buildStatus/icon?job=rocksdb&style=plastic)](http://140-211-168-68-openstack.osuosl.org:8080/job/rocksdb)
7
+
8
+ RocksDB is developed and maintained by Facebook Database Engineering Team.
9
+ It is built on earlier work on [LevelDB](https://github.com/google/leveldb) by Sanjay Ghemawat (sanjay@google.com)
10
+ and Jeff Dean (jeff@google.com)
11
+
12
+ This code is a library that forms the core building block for a fast
13
+ key-value server, especially suited for storing data on flash drives.
14
+ It has a Log-Structured-Merge-Database (LSM) design with flexible tradeoffs
15
+ between Write-Amplification-Factor (WAF), Read-Amplification-Factor (RAF)
16
+ and Space-Amplification-Factor (SAF). It has multi-threaded compactions,
17
+ making it especially suitable for storing multiple terabytes of data in a
18
+ single database.
19
+
20
+ Start with example usage here: https://github.com/facebook/rocksdb/tree/master/examples
21
+
22
+ See the [github wiki](https://github.com/facebook/rocksdb/wiki) for more explanation.
23
+
24
+ The public interface is in `include/`. Callers should not include or
25
+ rely on the details of any other header files in this package. Those
26
+ internal APIs may be changed without warning.
27
+
28
+ Design discussions are conducted in https://www.facebook.com/groups/rocksdb.dev/ and https://rocksdb.slack.com/
29
+
30
+ ## License
31
+
32
+ RocksDB is dual-licensed under both the GPLv2 (found in the COPYING file in the root directory) and Apache 2.0 License (found in the LICENSE.Apache file in the root directory). You may select, at your option, one of the above-listed licenses.
@@ -0,0 +1,23 @@
1
+ This directory contains the hdfs extensions needed to make rocksdb store
2
+ files in HDFS.
3
+
4
+ It has been compiled and testing against CDH 4.4 (2.0.0+1475-1.cdh4.4.0.p0.23~precise-cdh4.4.0).
5
+
6
+ The configuration assumes that packages libhdfs0, libhdfs0-dev are
7
+ installed which basically means that hdfs.h is in /usr/include and libhdfs in /usr/lib
8
+
9
+ The env_hdfs.h file defines the rocksdb objects that are needed to talk to an
10
+ underlying filesystem.
11
+
12
+ If you want to compile rocksdb with hdfs support, please set the following
13
+ environment variables appropriately (also defined in setup.sh for convenience)
14
+ USE_HDFS=1
15
+ JAVA_HOME=/usr/local/jdk-7u79-64
16
+ LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/jdk-7u79-64/jre/lib/amd64/server:/usr/local/jdk-7u79-64/jre/lib/amd64/:./snappy/libs
17
+ make clean all db_bench
18
+
19
+ To run dbbench,
20
+ set CLASSPATH to include your hadoop distribution
21
+ db_bench --hdfs="hdfs://hbaseudbperf001.snc1.facebook.com:9000"
22
+
23
+
@@ -0,0 +1,10 @@
1
+ This directory contains interfaces and implementations that isolate the
2
+ rest of the package from platform details.
3
+
4
+ Code in the rest of the package includes "port.h" from this directory.
5
+ "port.h" in turn includes a platform specific "port_<platform>.h" file
6
+ that provides the platform specific implementation.
7
+
8
+ See port_posix.h for an example of what must be provided in a platform
9
+ specific header file.
10
+