aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/DB.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-04 08:23:51 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-04 08:23:51 +0100
commit761330ff6ee1febb0ecb223b6244416248b7f894 (patch)
tree23eca325df35f67babfaa2330622be1b1fd7f8e8 /src/crepe/DB.cpp
parenta2607bffb1c0f8699021b1b4b3e54fa372e3ed0a (diff)
finish get/set implementations on DB
Diffstat (limited to 'src/crepe/DB.cpp')
-rw-r--r--src/crepe/DB.cpp12
1 files changed, 6 insertions, 6 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 (...) {