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.