Skip to content

Commit

Permalink
db/DB.js: prevent DB layer from returning undefined
Browse files Browse the repository at this point in the history
ueberDB2 can return either undefined or null for a missing key, depending on
which DB driver is used. This patch changes the promise version of the API so
that it will always return null.
  • Loading branch information
raybellis committed Mar 5, 2019
1 parent 7699337 commit ac7663c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/node/db/DB.js
Expand Up @@ -51,6 +51,19 @@ exports.init = function() {
exports[fn] = util.promisify(db[fn].bind(db));
});

// set up wrappers for get and getSub that can't return "undefined"
let get = exports.get;
exports.get = async function(key) {
let result = await get(key);
return (result === undefined) ? null : result;
};

let getSub = exports.getSub;
exports.getSub = async function(key, sub) {
let result = await getSub(key, sub);
return (result === undefined) ? null : result;
};

// exposed for those callers that need the underlying raw API
exports.db = db;
resolve();
Expand Down

0 comments on commit ac7663c

Please sign in to comment.