You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
536 B
JavaScript

"use strict";
const Promise = require("bluebird");
const mapObj = require("map-obj");
const databaseError = require("database-error");
function wrapMethod(value) {
if (typeof value === "function") {
return function wrappedDatabaseMethod(...args) {
return Promise.try(() => {
return value.call(this, ...args);
}).catch(databaseError.rethrow);
};
} else {
return value;
}
}
module.exports = function createDatabaseModule(methods) {
return mapObj(methods, (key, value) => {
return [key, wrapMethod(value)];
});
};