aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/crepe/DB.cpp12
-rw-r--r--src/crepe/DB.h4
2 files changed, 8 insertions, 8 deletions
diff --git a/src/crepe/DB.cpp b/src/crepe/DB.cpp
index b188637..bd2f089 100644
--- a/src/crepe/DB.cpp
+++ b/src/crepe/DB.cpp
@@ -31,7 +31,7 @@ DB::DB(const string & path) {
}
-libdb::DBT DB::to_thing(const string & thing) {
+libdb::DBT DB::to_thing(const string & thing) const {
libdb::DBT thang;
memset(&thang, 0, sizeof(libdb::DBT));
thang.data = (void *) thing.data();
@@ -44,19 +44,19 @@ string DB::get(const string & key) {
libdb::DBT db_val;
memset(&db_val, 0, sizeof(libdb::DBT));
- // int ret = this->cursor->get(this->cursor.get(), NULL, &db_key, &db_val);
- return "";
+ int ret = this->cursor->get(this->cursor.get(), &db_key, &db_val, DB_FIRST);
+ if (ret != 0) throw nullptr; // TODO: proper exception
+ return { static_cast<char *>(db_val.data), db_val.size };
}
void DB::set(const string & key, const string & value) {
libdb::DBT db_key = this->to_thing(key);
libdb::DBT db_val = this->to_thing(value);
int ret = this->db->put(this->db.get(), NULL, &db_key, &db_val, 0);
- // TODO: check flags
- // TODO: check ret
+ if (ret != 0) throw nullptr; // TODO: proper exception
}
-bool DB::has(const std::string & key) {
+bool DB::has(const std::string & key) noexcept {
try {
this->get(key);
} catch (...) {
diff --git a/src/crepe/DB.h b/src/crepe/DB.h
index c331f95..06442ad 100644
--- a/src/crepe/DB.h
+++ b/src/crepe/DB.h
@@ -20,14 +20,14 @@ public:
public:
std::string get(const std::string & key);
void set(const std::string & key, const std::string & value);
- bool has(const std::string & key);
+ bool has(const std::string & key) noexcept;
private:
std::unique_ptr<libdb::DB, std::function<void(libdb::DB *)>> db;
std::unique_ptr<libdb::DBC, std::function<void(libdb::DBC *)>> cursor;
private:
- libdb::DBT to_thing(const std::string & thing);
+ libdb::DBT to_thing(const std::string & thing) const;
};
}