@nxtedition/rocksdb 7.0.17 → 7.0.20

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,19 +983,29 @@ 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());
999
994
  cache_.emplace_back(std::nullopt);
1000
995
  }
1001
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");
1005
+ cache_.emplace_back(std::nullopt);
1006
+ cache_.emplace_back(data.ToStringView());
1007
+ }
1008
+
1002
1009
  bool Continue() override { return true; }
1003
1010
 
1004
1011
  private:
@@ -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));
@@ -1626,6 +1630,22 @@ NAPI_METHOD(batch_do) {
1626
1630
  NAPI_STATUS_THROWS(ToString(env, valueProperty, value));
1627
1631
 
1628
1632
  ROCKS_STATUS_THROWS(batch.Put(column, key, value));
1633
+ } else if (type == "data") {
1634
+ napi_value valueProperty;
1635
+ NAPI_STATUS_THROWS(napi_get_named_property(env, element, "value", &valueProperty));
1636
+ NAPI_STATUS_THROWS(ToString(env, valueProperty, value));
1637
+
1638
+ ROCKS_STATUS_THROWS(batch.PutLogData(value));
1639
+ } else if (type == "merge") {
1640
+ napi_value keyProperty;
1641
+ NAPI_STATUS_THROWS(napi_get_named_property(env, element, "key", &keyProperty));
1642
+ NAPI_STATUS_THROWS(ToString(env, keyProperty, key));
1643
+
1644
+ napi_value valueProperty;
1645
+ NAPI_STATUS_THROWS(napi_get_named_property(env, element, "value", &valueProperty));
1646
+ NAPI_STATUS_THROWS(ToString(env, valueProperty, value));
1647
+
1648
+ ROCKS_STATUS_THROWS(batch.Merge(column, key, value));
1629
1649
  } else {
1630
1650
  ROCKS_STATUS_THROWS(rocksdb::Status::InvalidArgument());
1631
1651
  }
@@ -1720,6 +1740,46 @@ NAPI_METHOD(batch_write) {
1720
1740
  return 0;
1721
1741
  }
1722
1742
 
1743
+ NAPI_METHOD(batch_put_log_data) {
1744
+ NAPI_ARGV(4);
1745
+
1746
+ Database* database;
1747
+ NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&database)));
1748
+
1749
+ rocksdb::WriteBatch* batch;
1750
+ NAPI_STATUS_THROWS(napi_get_value_external(env, argv[1], reinterpret_cast<void**>(&batch)));
1751
+
1752
+ std::string logData;
1753
+ NAPI_STATUS_THROWS(ToString(env, argv[2], logData));
1754
+
1755
+ ROCKS_STATUS_THROWS(batch->PutLogData(logData));
1756
+
1757
+ return 0;
1758
+ }
1759
+
1760
+ NAPI_METHOD(batch_merge) {
1761
+ NAPI_ARGV(5);
1762
+
1763
+ Database* database;
1764
+ NAPI_STATUS_THROWS(napi_get_value_external(env, argv[0], reinterpret_cast<void**>(&database)));
1765
+
1766
+ rocksdb::WriteBatch* batch;
1767
+ NAPI_STATUS_THROWS(napi_get_value_external(env, argv[1], (void**)(&batch)));
1768
+
1769
+ std::string key;
1770
+ NAPI_STATUS_THROWS(ToString(env, argv[2], key));
1771
+
1772
+ std::string val;
1773
+ NAPI_STATUS_THROWS(ToString(env, argv[3], val));
1774
+
1775
+ rocksdb::ColumnFamilyHandle* column;
1776
+ NAPI_STATUS_THROWS(GetColumnFamily(database, env, argv[4], &column));
1777
+
1778
+ ROCKS_STATUS_THROWS(batch->Merge(column, key, val));
1779
+
1780
+ return 0;
1781
+ }
1782
+
1723
1783
  NAPI_INIT() {
1724
1784
  NAPI_EXPORT_FUNCTION(db_init);
1725
1785
  NAPI_EXPORT_FUNCTION(db_open);
@@ -1748,4 +1808,6 @@ NAPI_INIT() {
1748
1808
  NAPI_EXPORT_FUNCTION(batch_del);
1749
1809
  NAPI_EXPORT_FUNCTION(batch_clear);
1750
1810
  NAPI_EXPORT_FUNCTION(batch_write);
1811
+ NAPI_EXPORT_FUNCTION(batch_put_log_data);
1812
+ NAPI_EXPORT_FUNCTION(batch_merge);
1751
1813
  }
package/chained-batch.js CHANGED
@@ -38,6 +38,16 @@ 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
+ }
46
+
47
+ merge (key, value, options) {
48
+ // TODO (fix): Check if open...
49
+ binding.batch_merge(this[kDbContext], this[kBatchContext], key, value, options)
50
+ }
41
51
  }
42
52
 
43
53
  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
 
@@ -251,11 +251,11 @@ class RocksLevel extends AbstractLevel {
251
251
  const updates = new Updates(this, options)
252
252
  try {
253
253
  while (true) {
254
- const { sequence, rows } = await updates.next()
255
- if (!rows) {
254
+ const entry = await updates.next()
255
+ if (!entry.rows) {
256
256
  return
257
257
  }
258
- yield { sequence: Number(sequence), rows }
258
+ yield entry
259
259
  }
260
260
  } finally {
261
261
  await updates.close()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/rocksdb",
3
- "version": "7.0.17",
3
+ "version": "7.0.20",
4
4
  "description": "A low-level Node.js RocksDB binding",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
Binary file
Binary file