Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ldb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ R"(ldb

Usage:
ldb <path> [--create] [--error] [--size] [--nocompress]
ldb <path> (del|get) <key>
ldb <path> (del|get|getbin) <key>
ldb <path> put <key> <value> [--nocompress]
ldb <path> keys [--limit=<n>] [--lower=<lower>] [--upper=<upper>]
ldb (-h | --help)
Expand Down Expand Up @@ -106,6 +106,7 @@ int main(int argc, const char** argv)
if (args["del"].asBool() ||
args["put"].asBool() ||
args["get"].asBool() ||
args["getbin"].asBool() ||
args["keys"].asBool() ||
args["--size"].asBool()) {
interactive = false;
Expand Down Expand Up @@ -145,6 +146,9 @@ int main(int argc, const char** argv)
if (args["get"] && args["get"].asBool()) {
ldb::get_value(args["<key>"].asString());
}
else if (args["getbin"] && args["getbin"].asBool()) {
ldb::get_value_bin(args["<key>"].asString());
}
else if (args["put"] && args["put"].asBool()) {

string key = args["<key>"].asString();
Expand Down
1 change: 1 addition & 0 deletions ldb.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace ldb {
void auto_completion(const char *buf, linenoiseCompletions *lc);
void put_value(string key, string value);
void get_value(string key);
void get_value_bin(string key);
void del_value(string key);
void get_size();
void range(string prefix, bool surpress_output);
Expand Down
13 changes: 13 additions & 0 deletions lib/commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ void ldb::get_value(string key) {
}
}

void ldb::get_value_bin(string key) {
if (key == "") return;

string value;
leveldb::Status status = db->Get(leveldb::ReadOptions(), key, &value);

if (!status.ok()) {
cerr << "Not Found: [" << COLOR_BLUE << key << COLOR_NONE << "]" << endl;
} else {
cout << value;
}
}

//
//
//
Expand Down