LevelDB二级索引实现 姚凯文(kevinyao0901) 姜嘉祺
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
975 B

  1. #include "leveldb/db.h"
  2. #include "leveldb/env.h" // 添加对 Env 类的完整定义
  3. #include <iostream>
  4. using namespace std;
  5. using namespace leveldb;
  6. int main() {
  7. DB* db = nullptr;
  8. Options op;
  9. op.create_if_missing = true;
  10. // 创建日志文件并将其关联到 Options 的 info_log
  11. Logger* logger;
  12. Status log_status = Env::Default()->NewLogger("leveldb_log.txt", &logger);
  13. if (log_status.ok()) {
  14. op.info_log = logger; // 正确设置 Logger 指针
  15. } else {
  16. cerr << "Failed to create logger: " << log_status.ToString() << endl;
  17. }
  18. Status status = DB::Open(op, "testWAL", &db);
  19. assert(status.ok());
  20. db->Put(WriteOptions(), "001", "leveldb");
  21. string s;
  22. db->Get(ReadOptions(), "001", &s);
  23. cout<<s<<endl;
  24. db->Put(WriteOptions(), "002", "world");
  25. string s1;
  26. db->Delete(WriteOptions(), "002");
  27. db->Get(ReadOptions(), "002", &s1);
  28. cout<<s1<<endl;
  29. delete db;
  30. return 0;
  31. }