Skip to content

Commit

Permalink
Implement db_get_property()
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphtheninja committed Dec 15, 2018
1 parent a1f94da commit ce049dd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions binding.cc
Expand Up @@ -386,6 +386,10 @@ struct Database {
db_->CompactRange(start, end);
}

void GetProperty (const leveldb::Slice& property, std::string* value) {
db_->GetProperty(property, value);
}

const leveldb::Snapshot* NewSnapshot () {
return db_->GetSnapshot();
}
Expand Down Expand Up @@ -1160,6 +1164,25 @@ NAPI_METHOD(db_compact_range) {
NAPI_RETURN_UNDEFINED();
}

/**
* Get a property from a database.
*/
NAPI_METHOD(db_get_property) {
NAPI_ARGV(2);
NAPI_DB_CONTEXT();

leveldb::Slice property = ToSlice(env, argv[1]);

std::string value;
database->GetProperty(property, &value);

napi_value result;
napi_create_string_utf8(env, value.data(), value.size(), &result);

// TODO clean up property slice
return result;
}

/**
* Worker class for destroying a database.
*/
Expand Down Expand Up @@ -1900,6 +1923,7 @@ NAPI_INIT() {
NAPI_EXPORT_FUNCTION(db_del);
NAPI_EXPORT_FUNCTION(db_approximate_size);
NAPI_EXPORT_FUNCTION(db_compact_range);
NAPI_EXPORT_FUNCTION(db_get_property);

NAPI_EXPORT_FUNCTION(destroy_db);
NAPI_EXPORT_FUNCTION(repair_db);
Expand Down
2 changes: 1 addition & 1 deletion leveldown.js
Expand Up @@ -98,7 +98,7 @@ LevelDOWN.prototype.getProperty = function (property) {
throw new Error('getProperty() requires a valid `property` argument')
}

return this.binding.getProperty(property)
return binding.db_get_property(this.context, property)
}

LevelDOWN.prototype._iterator = function (options) {
Expand Down

0 comments on commit ce049dd

Please sign in to comment.