Loading AI tools
来自维基百科,自由的百科全书
LevelDB是一个由Google公司所研发的键-值存储嵌入式数据库管理系统编程库,[2] 以开源的BSD许可证发布。[3]
储存键/值对,和查询键的值:
#include "leveldb/db.h"
#include <iostream>
using namespace std;
int main(){
leveldb::DB *db;
leveldb::Options options;
options.create_if_missing = true;
// 開啟數據庫
leveldb::DB::Open(options, "/tmp/testdb", &db);
// 鍵 = MyKey29,值 = "Hello World!"
string key = "MyKey29", value = "Hello World!", result;
// 儲存 鍵/值對
db->Put(leveldb::WriteOptions(), key, value);
// 查詢 MyKey29 鍵的值
db->Get(leveldb::ReadOptions(), key, &result);
// 輸出值到屏幕
cout << "result = " << result << endl;
// 關閉數據庫
delete db;
return 0;
}
(LevelDB安装目录为:leveldb-read-only)[6]
% g++ test.cc -Ileveldb-read-only/include -Lleveldb-read-only -lleveldb -lpthread % ./a.out result = Hello World!
Seamless Wikipedia browsing. On steroids.
Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.
Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.