Skip to content

Instantly share code, notes, and snippets.

@raaka1
Created December 11, 2016 14:43
Show Gist options
  • Select an option

  • Save raaka1/8a0c6627f0db610ea9b4e68191781eef to your computer and use it in GitHub Desktop.

Select an option

Save raaka1/8a0c6627f0db610ea9b4e68191781eef to your computer and use it in GitHub Desktop.
LEVELDB hello world
#include <cassert>
#include <leveldb/db.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
leveldb::DB* db;
leveldb::Options options;
options.create_if_missing = true;
leveldb::Status status = leveldb::DB::Open(options, "/tmp/testdb", &db);
assert(status.ok());
string key = "foo";
string value = "bar";
cout << "write Key:" << key << " and value:" << value << endl;
status = db->Put(leveldb::WriteOptions(), key, value);
assert(status.ok());
string value_back;
status = db->Get(leveldb::ReadOptions(), key, &value_back);
cout << "Read back:" << value_back << endl;
assert(status.ok());
assert(value == value_back);
delete db;
return 0;
}
//http://wiki.dreamrunner.org/public_html/C-C++/Library-Notes/LevelDB.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment