@nxtedition/rocksdb 5.2.10 → 5.2.17

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.2.16] - 2022-04-20
4
+
5
+ ## [5.2.15] - 2022-04-20
6
+
7
+ ## [5.2.14] - 2022-04-20
8
+
3
9
  ## [5.2.1] - 2022-03-25
4
10
 
5
11
  ### Fixed
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,
@@ -857,6 +861,8 @@ struct OpenWorker final : public BaseWorker {
857
861
  tableOptions.block_size = blockSize;
858
862
  tableOptions.block_restart_interval = blockRestartInterval;
859
863
  tableOptions.filter_policy.reset(rocksdb::NewBloomFilterPolicy(10));
864
+ tableOptions.format_version = 5;
865
+ tableOptions.checksum = rocksdb::kxxHash64;
860
866
 
861
867
  options_.table_factory.reset(
862
868
  rocksdb::NewBlockBasedTableFactory(tableOptions)
@@ -876,7 +882,7 @@ NAPI_METHOD(db_open) {
876
882
  NAPI_ARGV(4);
877
883
  NAPI_DB_CONTEXT();
878
884
 
879
- const auto location = ToString(env, argv[1]).value_or(std::string());
885
+ const auto location = ToString(env, argv[1]);
880
886
  const auto options = argv[2];
881
887
  const auto createIfMissing = BooleanProperty(env, options, "createIfMissing", true);
882
888
  const auto errorIfExists = BooleanProperty(env, options, "errorIfExists", false);
@@ -952,7 +958,7 @@ struct PutWorker final : public PriorityWorker {
952
958
  const std::string& key,
953
959
  const std::string& value,
954
960
  bool sync)
955
- : PriorityWorker(env, database, callback, "classic_level.db.put"),
961
+ : PriorityWorker(env, database, callback, "rocks_level.db.put"),
956
962
  key_(key), value_(value), sync_(sync) {
957
963
  }
958
964
 
@@ -971,8 +977,8 @@ NAPI_METHOD(db_put) {
971
977
  NAPI_ARGV(5);
972
978
  NAPI_DB_CONTEXT();
973
979
 
974
- const auto key = ToString(env, argv[1]).value_or(std::string());
975
- const auto value = ToString(env, argv[2]).value_or(std::string());
980
+ const auto key = ToString(env, argv[1]);
981
+ const auto value = ToString(env, argv[2]);
976
982
  const auto sync = BooleanProperty(env, argv[3], "sync", false);
977
983
  const auto callback = argv[4];
978
984
 
@@ -989,7 +995,7 @@ struct GetWorker final : public PriorityWorker {
989
995
  const std::string& key,
990
996
  const bool asBuffer,
991
997
  const bool fillCache)
992
- : PriorityWorker(env, database, callback, "classic_level.db.get"),
998
+ : PriorityWorker(env, database, callback, "rocks_level.db.get"),
993
999
  key_(key), asBuffer_(asBuffer), fillCache_(fillCache) {
994
1000
  }
995
1001
 
@@ -1017,7 +1023,7 @@ NAPI_METHOD(db_get) {
1017
1023
  NAPI_ARGV(4);
1018
1024
  NAPI_DB_CONTEXT();
1019
1025
 
1020
- const auto key = ToString(env, argv[1]).value_or(std::string());
1026
+ const auto key = ToString(env, argv[1]);
1021
1027
  const auto options = argv[2];
1022
1028
  const auto asBuffer = EncodingIsBuffer(env, options, "valueEncoding");
1023
1029
  const auto fillCache = BooleanProperty(env, options, "fillCache", true);
@@ -1029,7 +1035,6 @@ NAPI_METHOD(db_get) {
1029
1035
  return 0;
1030
1036
  }
1031
1037
 
1032
-
1033
1038
  struct GetManyWorker final : public PriorityWorker {
1034
1039
  GetManyWorker (napi_env env,
1035
1040
  Database* database,
@@ -1062,9 +1067,9 @@ struct GetManyWorker final : public PriorityWorker {
1062
1067
  const auto status = database_->Get(options, key, value);
1063
1068
 
1064
1069
  if (status.ok()) {
1065
- cache_.push_back(std::move(value));
1070
+ cache_.emplace_back(std::move(value));
1066
1071
  } else if (status.IsNotFound()) {
1067
- cache_.push_back({});
1072
+ cache_.emplace_back(nullptr);
1068
1073
  } else {
1069
1074
  SetStatus(status);
1070
1075
  break;
@@ -1085,7 +1090,11 @@ struct GetManyWorker final : public PriorityWorker {
1085
1090
 
1086
1091
  for (size_t idx = 0; idx < size; idx++) {
1087
1092
  napi_value element;
1088
- Convert(env, cache_[idx], valueAsBuffer_, element);
1093
+ if (cache_[idx].GetSelf() != nullptr) {
1094
+ Convert(env, cache_[idx], valueAsBuffer_, element);
1095
+ } else {
1096
+ napi_get_undefined(env, &element);
1097
+ }
1089
1098
  napi_set_element(env, array, static_cast<uint32_t>(idx), element);
1090
1099
  }
1091
1100
 
@@ -1098,7 +1107,7 @@ struct GetManyWorker final : public PriorityWorker {
1098
1107
  private:
1099
1108
  const std::vector<std::string> keys_;
1100
1109
  const bool valueAsBuffer_;
1101
- std::vector<std::optional<rocksdb::PinnableSlice>> cache_;
1110
+ std::vector<rocksdb::PinnableSlice> cache_;
1102
1111
  const bool fillCache_;
1103
1112
  const leveldb::Snapshot* snapshot_;
1104
1113
  };
@@ -1125,7 +1134,7 @@ struct DelWorker final : public PriorityWorker {
1125
1134
  napi_value callback,
1126
1135
  const std::string& key,
1127
1136
  bool sync)
1128
- : PriorityWorker(env, database, callback, "classic_level.db.del"),
1137
+ : PriorityWorker(env, database, callback, "rocks_level.db.del"),
1129
1138
  key_(key), sync_(sync) {
1130
1139
  }
1131
1140
 
@@ -1143,7 +1152,7 @@ NAPI_METHOD(db_del) {
1143
1152
  NAPI_ARGV(4);
1144
1153
  NAPI_DB_CONTEXT();
1145
1154
 
1146
- const auto key = ToString(env, argv[1]).value_or(std::string());
1155
+ const auto key = ToString(env, argv[1]);
1147
1156
  const auto sync = BooleanProperty(env, argv[2], "sync", false);
1148
1157
  const auto callback = argv[3];
1149
1158
 
@@ -1159,11 +1168,11 @@ struct ClearWorker final : public PriorityWorker {
1159
1168
  napi_value callback,
1160
1169
  const bool reverse,
1161
1170
  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"),
1171
+ const std::string* lt,
1172
+ const std::string* lte,
1173
+ const std::string* gt,
1174
+ const std::string* gte)
1175
+ : PriorityWorker(env, database, callback, "rocks_level.db.clear"),
1167
1176
  iterator_(database, reverse, lt, lte, gt, gte, limit, false) {
1168
1177
  }
1169
1178
 
@@ -1226,6 +1235,150 @@ NAPI_METHOD(db_clear) {
1226
1235
  return 0;
1227
1236
  }
1228
1237
 
1238
+ struct ApproximateSizeWorker final : public PriorityWorker {
1239
+ ApproximateSizeWorker (napi_env env,
1240
+ Database* database,
1241
+ napi_value callback,
1242
+ const std::string& start,
1243
+ const std::string& end)
1244
+ : PriorityWorker(env, database, callback, "rocks_level.db.approximate_size"),
1245
+ start_(start), end_(end) {}
1246
+
1247
+ void DoExecute () override {
1248
+ leveldb::Range range(start_, end_);
1249
+ size_ = database_->ApproximateSize(&range);
1250
+ }
1251
+
1252
+ void HandleOKCallback (napi_env env, napi_value callback) override {
1253
+ napi_value argv[2];
1254
+ napi_get_null(env, &argv[0]);
1255
+ napi_create_int64(env, size_, &argv[1]);
1256
+ CallFunction(env, callback, 2, argv);
1257
+ }
1258
+
1259
+ std::string start_;
1260
+ std::string end_;
1261
+ uint64_t size_;
1262
+ };
1263
+
1264
+ NAPI_METHOD(db_approximate_size) {
1265
+ NAPI_ARGV(4);
1266
+ NAPI_DB_CONTEXT();
1267
+
1268
+ const auto start = ToString(env, argv[1]);
1269
+ const auto end = ToString(env, argv[2]);
1270
+ const auto callback = argv[3];
1271
+
1272
+ auto worker = new ApproximateSizeWorker(env, database, callback, start, end);
1273
+ worker->Queue(env);
1274
+
1275
+ return 0;
1276
+ }
1277
+
1278
+ struct CompactRangeWorker final : public PriorityWorker {
1279
+ CompactRangeWorker (napi_env env,
1280
+ Database* database,
1281
+ napi_value callback,
1282
+ const std::string& start,
1283
+ const std::string& end)
1284
+ : PriorityWorker(env, database, callback, "rocks_level.db.compact_range"),
1285
+ start_(start), end_(end) {}
1286
+
1287
+ void DoExecute () override {
1288
+ leveldb::Slice start = start_;
1289
+ leveldb::Slice end = end_;
1290
+ database_->CompactRange(&start, &end);
1291
+ }
1292
+
1293
+ const std::string start_;
1294
+ const std::string end_;
1295
+ };
1296
+
1297
+ NAPI_METHOD(db_compact_range) {
1298
+ NAPI_ARGV(4);
1299
+ NAPI_DB_CONTEXT();
1300
+
1301
+ const auto start = ToString(env, argv[1]);
1302
+ const auto end = ToString(env, argv[2]);
1303
+ const auto callback = argv[3];
1304
+
1305
+ auto worker = new CompactRangeWorker(env, database, callback, start, end);
1306
+ worker->Queue(env);
1307
+
1308
+ return 0;
1309
+ }
1310
+
1311
+ NAPI_METHOD(db_get_property) {
1312
+ NAPI_ARGV(2);
1313
+ NAPI_DB_CONTEXT();
1314
+
1315
+ const auto property = ToString(env, argv[1]);
1316
+
1317
+ std::string value;
1318
+ database->GetProperty(property, value);
1319
+
1320
+ napi_value result;
1321
+ napi_create_string_utf8(env, value.data(), value.size(), &result);
1322
+
1323
+ return result;
1324
+ }
1325
+
1326
+ struct DestroyWorker final : public BaseWorker {
1327
+ DestroyWorker (napi_env env,
1328
+ const std::string& location,
1329
+ napi_value callback)
1330
+ : BaseWorker(env, nullptr, callback, "rocks_level.destroy_db"),
1331
+ location_(location) {}
1332
+
1333
+ ~DestroyWorker () {}
1334
+
1335
+ void DoExecute () override {
1336
+ leveldb::Options options;
1337
+ SetStatus(leveldb::DestroyDB(location_, options));
1338
+ }
1339
+
1340
+ const std::string location_;
1341
+ };
1342
+
1343
+ NAPI_METHOD(destroy_db) {
1344
+ NAPI_ARGV(2);
1345
+
1346
+ const auto location = ToString(env, argv[0]);
1347
+ const auto callback = argv[1];
1348
+
1349
+ auto worker = new DestroyWorker(env, location, callback);
1350
+ worker->Queue(env);
1351
+
1352
+ return 0;
1353
+ }
1354
+
1355
+ struct RepairWorker final : public BaseWorker {
1356
+ RepairWorker (napi_env env,
1357
+ const std::string& location,
1358
+ napi_value callback)
1359
+ : BaseWorker(env, nullptr, callback, "rocks_level.repair_db"),
1360
+ location_(location) {}
1361
+
1362
+ void DoExecute () override {
1363
+ leveldb::Options options;
1364
+ SetStatus(leveldb::RepairDB(location_, options));
1365
+ }
1366
+
1367
+ const std::string location_;
1368
+ };
1369
+
1370
+ NAPI_METHOD(repair_db) {
1371
+ NAPI_ARGV(2);
1372
+
1373
+ const auto location = ToString(env, argv[1]);
1374
+ const auto callback = argv[1];
1375
+
1376
+ auto worker = new RepairWorker(env, location, callback);
1377
+ worker->Queue(env);
1378
+
1379
+ return 0;
1380
+ }
1381
+
1229
1382
  static void FinalizeIterator (napi_env env, void* data, void* hint) {
1230
1383
  if (data) {
1231
1384
  delete reinterpret_cast<Iterator*>(data);
@@ -1275,7 +1428,7 @@ NAPI_METHOD(iterator_seek) {
1275
1428
  napi_throw_error(env, nullptr, "iterator has closed");
1276
1429
  }
1277
1430
 
1278
- const auto target = ToString(env, argv[1]).value_or(std::string());
1431
+ const auto target = ToString(env, argv[1]);
1279
1432
  iterator->first_ = true;
1280
1433
  iterator->Seek(target);
1281
1434
 
@@ -1427,7 +1580,7 @@ struct BatchWorker final : public PriorityWorker {
1427
1580
  leveldb::WriteBatch* batch,
1428
1581
  const bool sync,
1429
1582
  const bool hasData)
1430
- : PriorityWorker(env, database, callback, "classic_level.batch.do"),
1583
+ : PriorityWorker(env, database, callback, "rocks_level.batch.do"),
1431
1584
  batch_(batch), hasData_(hasData) {
1432
1585
  options_.sync = sync;
1433
1586
  }
@@ -1472,7 +1625,7 @@ NAPI_METHOD(batch_do) {
1472
1625
 
1473
1626
  if (type == "del") {
1474
1627
  if (!HasProperty(env, element, "key")) continue;
1475
- const auto key = ToString(env, GetProperty(env, element, "key")).value_or(std::string());
1628
+ const auto key = ToString(env, GetProperty(env, element, "key"));
1476
1629
 
1477
1630
  batch->Delete(key);
1478
1631
  if (!hasData) hasData = true;
@@ -1480,8 +1633,8 @@ NAPI_METHOD(batch_do) {
1480
1633
  if (!HasProperty(env, element, "key")) continue;
1481
1634
  if (!HasProperty(env, element, "value")) continue;
1482
1635
 
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());
1636
+ const auto key = ToString(env, GetProperty(env, element, "key"));
1637
+ const auto value = ToString(env, GetProperty(env, element, "value"));
1485
1638
 
1486
1639
  batch->Put(key, value);
1487
1640
  if (!hasData) hasData = true;
@@ -1517,8 +1670,8 @@ NAPI_METHOD(batch_put) {
1517
1670
  NAPI_ARGV(3);
1518
1671
  NAPI_BATCH_CONTEXT();
1519
1672
 
1520
- const auto key = ToString(env, argv[1]).value_or(std::string());
1521
- const auto value = ToString(env, argv[2]).value_or(std::string());
1673
+ const auto key = ToString(env, argv[1]);
1674
+ const auto value = ToString(env, argv[2]);
1522
1675
 
1523
1676
  batch->Put(key, value);
1524
1677
 
@@ -1529,7 +1682,7 @@ NAPI_METHOD(batch_del) {
1529
1682
  NAPI_ARGV(2);
1530
1683
  NAPI_BATCH_CONTEXT();
1531
1684
 
1532
- const auto key = ToString(env, argv[1]).value_or(std::string());
1685
+ const auto key = ToString(env, argv[1]);
1533
1686
 
1534
1687
  batch->Delete(key);
1535
1688
 
@@ -1601,6 +1754,12 @@ NAPI_INIT() {
1601
1754
  NAPI_EXPORT_FUNCTION(db_get_many);
1602
1755
  NAPI_EXPORT_FUNCTION(db_del);
1603
1756
  NAPI_EXPORT_FUNCTION(db_clear);
1757
+ NAPI_EXPORT_FUNCTION(db_approximate_size);
1758
+ NAPI_EXPORT_FUNCTION(db_compact_range);
1759
+ NAPI_EXPORT_FUNCTION(db_get_property);
1760
+
1761
+ NAPI_EXPORT_FUNCTION(destroy_db);
1762
+ NAPI_EXPORT_FUNCTION(repair_db);
1604
1763
 
1605
1764
  NAPI_EXPORT_FUNCTION(iterator_init);
1606
1765
  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
+