create script callable from react

This commit is contained in:
Jan Prochazka
2020-02-03 20:34:38 +01:00
parent 680bed549f
commit 8a85cfe687
14 changed files with 147 additions and 95 deletions

View File

@@ -1,7 +1,25 @@
const _ = require("lodash");
const mssql = require('./mssql');
const mysql = require('./mysql');
const postgres = require('./postgres');
const drivers = {
mssql,
mysql,
postgres,
}
/** @return {import('@dbgate/types').EngineDriver} */
function getDriver(connection) {
const { engine } = connection;
return require(`./${engine}`);
if (_.isString(connection)) {
return drivers[connection];
}
if (_.isPlainObject(connection)) {
const { engine } = connection;
if (engine) {
return drivers[engine];
}
}
throw new Error(`Cannot extract engine from ${connection}`)
}
module.exports = getDriver;