From ac7663c3372853f1c79d0bf783b3d929ad6a4828 Mon Sep 17 00:00:00 2001 From: Ray Bellis Date: Tue, 5 Mar 2019 10:46:57 +0000 Subject: [PATCH] db/DB.js: prevent DB layer from returning undefined 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. --- src/node/db/DB.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/node/db/DB.js b/src/node/db/DB.js index 17cf3080..57356366 100644 --- a/src/node/db/DB.js +++ b/src/node/db/DB.js @@ -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();