backend - using engine driver from plugin

This commit is contained in:
Jan Prochazka
2020-11-24 20:42:02 +01:00
parent 424aff5d93
commit c96cb08cfd
9 changed files with 58 additions and 42 deletions

View File

@@ -0,0 +1,24 @@
const _ = require('lodash');
const requirePlugin = require('../shell/requirePlugin');
/** @returns {import('dbgate-types').EngineDriver} */
function requireEngineDriver(connection) {
let engine = null;
if (_.isString(connection)) {
engine = connection;
} else if (_.isPlainObject(connection)) {
engine = connection.engine;
}
if (!engine) {
throw new Error('Could not get driver from connection');
}
if (engine.includes('@')) {
const [shortName, packageName] = engine.split('@');
const plugin = requirePlugin(packageName);
return plugin.driver;
}
throw new Error(`Could not found engine driver ${engine}`);
}
module.exports = requireEngineDriver;