diff --git a/src/node/db/DB.js b/src/node/db/DB.js index 93848b1bd..fa94259b5 100644 --- a/src/node/db/DB.js +++ b/src/node/db/DB.js @@ -35,7 +35,7 @@ exports.db = null; * Initalizes the database with the settings provided by the settings module * @param {Function} callback */ -exports.init = function(callback) { +function init(callback) { // initalize the database async db.init(function(err) { if (err) { @@ -50,3 +50,19 @@ exports.init = function(callback) { } }); } + +/** + * Initalizes the database with the settings provided by the settings module + * If the callback is not supplied a Promise is returned instead. + * @param {Function} callback + */ +exports.init = function(callback) +{ + if (callback === undefined) { + return new Promise(resolve => init(resolve)); + } else if (typeof callback === "function") { + init(callback); + } else { + throw new TypeError("DB.init callback parameter"); + } +}