db_wrapper.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
  2. #ifndef DBWRAPPER_H
  3. #define DBWRAPPER_H
  4. #include <map>
  5. #include <node.h>
  6. #include "rocksdb/db.h"
  7. #include "rocksdb/slice.h"
  8. #include "rocksdb/options.h"
  9. using namespace v8;
  10. // Used to encapsulate a particular instance of an opened database.
  11. //
  12. // This object should not be used directly in C++; it exists solely to provide
  13. // a mapping from a JavaScript object to a C++ code that can use the RocksDB
  14. // API.
  15. class DBWrapper : public node::ObjectWrap {
  16. public:
  17. static void Init(Handle<Object> exports);
  18. private:
  19. explicit DBWrapper();
  20. ~DBWrapper();
  21. // Helper methods
  22. static bool HasFamilyNamed(std::string& name, DBWrapper* db);
  23. static bool AddToBatch(ROCKSDB_NAMESPACE::WriteBatch& batch, bool del,
  24. Handle<Array> array);
  25. static bool AddToBatch(ROCKSDB_NAMESPACE::WriteBatch& batch, bool del,
  26. Handle<Array> array, DBWrapper* db_wrapper,
  27. std::string cf);
  28. static Handle<Value> CompactRangeDefault(const v8::Arguments& args);
  29. static Handle<Value> CompactColumnFamily(const Arguments& args);
  30. static Handle<Value> CompactOptions(const Arguments& args);
  31. static Handle<Value> CompactAll(const Arguments& args);
  32. // C++ mappings of API methods
  33. static Persistent<v8::Function> constructor;
  34. static Handle<Value> Open(const Arguments& args);
  35. static Handle<Value> New(const Arguments& args);
  36. static Handle<Value> Get(const Arguments& args);
  37. static Handle<Value> Put(const Arguments& args);
  38. static Handle<Value> Delete(const Arguments& args);
  39. static Handle<Value> Dump(const Arguments& args);
  40. static Handle<Value> WriteBatch(const Arguments& args);
  41. static Handle<Value> CreateColumnFamily(const Arguments& args);
  42. static Handle<Value> CompactRange(const Arguments& args);
  43. static Handle<Value> Close(const Arguments& args);
  44. // Internal fields
  45. ROCKSDB_NAMESPACE::Options options_;
  46. ROCKSDB_NAMESPACE::Status status_;
  47. ROCKSDB_NAMESPACE::DB* db_;
  48. std::unordered_map<std::string, ROCKSDB_NAMESPACE::ColumnFamilyHandle*>
  49. columnFamilies_;
  50. };
  51. #endif