@nxtedition/rocksdb 7.0.16 → 7.0.19

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
@@ -539,11 +539,8 @@ struct Iterator final : public BaseIterator {
539
539
  };
540
540
 
541
541
  struct Updates {
542
- Updates(Database* database, bool values, bool keyAsBuffer, bool valueAsBuffer, int64_t seqNumber)
542
+ Updates(Database* database, int64_t seqNumber)
543
543
  : database_(database),
544
- values_(values),
545
- keyAsBuffer_(keyAsBuffer),
546
- valueAsBuffer_(valueAsBuffer),
547
544
  seqNumber_(seqNumber) {}
548
545
 
549
546
  void Close() { iterator_.reset(); }
@@ -561,9 +558,6 @@ struct Updates {
561
558
  }
562
559
 
563
560
  Database* database_;
564
- const bool values_;
565
- const bool keyAsBuffer_;
566
- const bool valueAsBuffer_;
567
561
  int64_t seqNumber_;
568
562
  std::unique_ptr<rocksdb::TransactionLogIterator> iterator_;
569
563
 
@@ -964,15 +958,18 @@ struct UpdatesNextWorker final : public rocksdb::WriteBatch::Handler, public Wor
964
958
  }
965
959
 
966
960
  NAPI_STATUS_RETURN(napi_create_array_with_length(env, cache_.size(), &argv[1]));
961
+ for (size_t idx = 0; idx < cache_.size(); idx += 3) {
962
+ napi_value op;
963
+ NAPI_STATUS_RETURN(Convert(env, cache_[idx + 0], false, op));
964
+ NAPI_STATUS_RETURN(napi_set_element(env, argv[1], static_cast<int>(idx + 0), op));
967
965
 
968
- for (size_t idx = 0; idx < cache_.size(); idx += 2) {
969
966
  napi_value key;
970
- NAPI_STATUS_RETURN(Convert(env, cache_[idx + 0], updates_->keyAsBuffer_, key));
971
- NAPI_STATUS_RETURN(napi_set_element(env, argv[1], static_cast<int>(idx + 0), key));
967
+ NAPI_STATUS_RETURN(Convert(env, cache_[idx + 1], false, key));
968
+ NAPI_STATUS_RETURN(napi_set_element(env, argv[1], static_cast<int>(idx + 1), key));
972
969
 
973
970
  napi_value val;
974
- NAPI_STATUS_RETURN(Convert(env, cache_[idx + 1], updates_->valueAsBuffer_, val));
975
- NAPI_STATUS_RETURN(napi_set_element(env, argv[1], static_cast<int>(idx + 1), val));
971
+ NAPI_STATUS_RETURN(Convert(env, cache_[idx + 2], false, val));
972
+ NAPI_STATUS_RETURN(napi_set_element(env, argv[1], static_cast<int>(idx + 2), val));
976
973
  }
977
974
 
978
975
  NAPI_STATUS_RETURN(napi_create_bigint_int64(env, updates_->seqNumber_, &argv[2]));
@@ -986,17 +983,27 @@ struct UpdatesNextWorker final : public rocksdb::WriteBatch::Handler, public Wor
986
983
  }
987
984
 
988
985
  void Put(const rocksdb::Slice& key, const rocksdb::Slice& value) override {
989
- cache_.emplace_back(key.ToString());
990
- if (updates_->values_) {
991
- cache_.emplace_back(value.ToString());
992
- } else {
993
- cache_.emplace_back(std::nullopt);
994
- }
986
+ cache_.emplace_back("put");
987
+ cache_.emplace_back(key.ToStringView());
988
+ cache_.emplace_back(value.ToStringView());
995
989
  }
996
990
 
997
991
  void Delete(const rocksdb::Slice& key) override {
998
- cache_.emplace_back(key.ToString());
992
+ cache_.emplace_back("del");
993
+ cache_.emplace_back(key.ToStringView());
994
+ cache_.emplace_back(std::nullopt);
995
+ }
996
+
997
+ void Merge(const rocksdb::Slice& key, const rocksdb::Slice& value) override {
998
+ cache_.emplace_back("merge");
999
+ cache_.emplace_back(key.ToStringView());
1000
+ cache_.emplace_back(value.ToStringView());
1001
+ }
1002
+
1003
+ void LogData(const rocksdb::Slice& data) override {
1004
+ cache_.emplace_back("data");
999
1005
  cache_.emplace_back(std::nullopt);
1006
+ cache_.emplace_back(data.ToStringView());
1000
1007
  }
1001
1008
 
1002
1009
  bool Continue() override { return true; }
@@ -1012,12 +1019,9 @@ NAPI_METHOD(updates_init) {
1012
1019
  Database* database;
1013
1020
  NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&database)));
1014
1021
 
1015
- const auto values = BooleanProperty(env, argv[1], "values").value_or(true);
1016
- const bool keyAsBuffer = EncodingIsBuffer(env, argv[1], "keyEncoding");
1017
- const bool valueAsBuffer = EncodingIsBuffer(env, argv[1], "valueEncoding");
1018
1022
  const auto seqNumber = Int64Property(env, argv[1], "since").value_or(database->db_->GetLatestSequenceNumber());
1019
1023
 
1020
- auto updates = std::make_unique<Updates>(database, values, keyAsBuffer, valueAsBuffer, seqNumber);
1024
+ auto updates = std::make_unique<Updates>(database, seqNumber);
1021
1025
 
1022
1026
  napi_value result;
1023
1027
  NAPI_STATUS_THROWS(napi_create_external(env, updates.get(), Finalize<Updates>, updates.get(), &result));
@@ -1720,6 +1724,23 @@ NAPI_METHOD(batch_write) {
1720
1724
  return 0;
1721
1725
  }
1722
1726
 
1727
+ NAPI_METHOD(batch_put_log_data) {
1728
+ NAPI_ARGV(4);
1729
+
1730
+ Database* database;
1731
+ NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&database)));
1732
+
1733
+ rocksdb::WriteBatch* batch;
1734
+ NAPI_STATUS_THROWS(napi_get_value_external(env, argv[1], reinterpret_cast<void**>(&batch)));
1735
+
1736
+ std::string logData;
1737
+ NAPI_STATUS_THROWS(ToString(env, argv[2], logData));
1738
+
1739
+ ROCKS_STATUS_THROWS(batch->PutLogData(logData));
1740
+
1741
+ return 0;
1742
+ }
1743
+
1723
1744
  NAPI_INIT() {
1724
1745
  NAPI_EXPORT_FUNCTION(db_init);
1725
1746
  NAPI_EXPORT_FUNCTION(db_open);
@@ -1748,4 +1769,5 @@ NAPI_INIT() {
1748
1769
  NAPI_EXPORT_FUNCTION(batch_del);
1749
1770
  NAPI_EXPORT_FUNCTION(batch_clear);
1750
1771
  NAPI_EXPORT_FUNCTION(batch_write);
1772
+ NAPI_EXPORT_FUNCTION(batch_put_log_data);
1751
1773
  }
package/chained-batch.js CHANGED
@@ -38,6 +38,11 @@ class ChainedBatch extends AbstractChainedBatch {
38
38
  _close (callback) {
39
39
  process.nextTick(callback)
40
40
  }
41
+
42
+ putLogData (data, options) {
43
+ // TODO (fix): Check if open...
44
+ binding.batch_put_log_data(this[kDbContext], this[kBatchContext], data, options)
45
+ }
41
46
  }
42
47
 
43
48
  exports.ChainedBatch = ChainedBatch
package/index.js CHANGED
@@ -208,12 +208,12 @@ class RocksLevel extends AbstractLevel {
208
208
  return {}
209
209
  }
210
210
 
211
- this.promise = new Promise(resolve => binding.updates_next(this.context, (err, rows, sequence) => {
211
+ this.promise = new Promise(resolve => binding.updates_next(this.context, (err, rows, sequence, data) => {
212
212
  this.promise = null
213
213
  if (err) {
214
214
  resolve(Promise.reject(err))
215
215
  } else {
216
- resolve({ rows, sequence })
216
+ resolve({ rows, data, sequence: Number(sequence) })
217
217
  }
218
218
  }))
219
219
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/rocksdb",
3
- "version": "7.0.16",
3
+ "version": "7.0.19",
4
4
  "description": "A low-level Node.js RocksDB binding",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
Binary file
Binary file