浏览代码

init

main
GUJIEJASON 3 周前
父节点
当前提交
c97d7cee71
共有 2 个文件被更改,包括 31 次插入0 次删除
  1. +5
    -0
      CMakeLists.txt
  2. +26
    -0
      test/db_test1.cc

+ 5
- 0
CMakeLists.txt 查看文件

@ -518,6 +518,11 @@ if(LEVELDB_INSTALL)
)
endif(LEVELDB_INSTALL)
add_executable(db_test1
"${PROJECT_SOURCE_DIR}/test/db_test1.cc"
)
target_link_libraries(db_test1 leveldb)
add_executable(db_test2
"${PROJECT_SOURCE_DIR}/test/db_test2.cc"

+ 26
- 0
test/db_test1.cc 查看文件

@ -0,0 +1,26 @@
#include "leveldb/db.h"
#include <iostream>
using namespace std;
using namespace leveldb;
int main() {
DB* db = nullptr;
Options op;
op.create_if_missing = true;
Status status = DB::Open(op, "testdb", &db);
assert(status.ok());
db->Put(WriteOptions(), "001", "leveldb");
string s;
db->Get(ReadOptions(), "001", &s);
cout<<s<<endl;
db->Put(WriteOptions(), "002", "world");
string s1;
db->Delete(WriteOptions(), "002");
db->Get(ReadOptions(), "002", &s1);
cout<<s1<<endl;
delete db;
return 0;
}

正在加载...
取消
保存