2020-02-03 19:34:38 +00:00
|
|
|
const _ = require("lodash");
|
2020-02-03 19:44:06 +00:00
|
|
|
const mssql = require("./mssql");
|
|
|
|
const mysql = require("./mysql");
|
|
|
|
const postgres = require("./postgres");
|
2020-02-03 19:34:38 +00:00
|
|
|
|
|
|
|
const drivers = {
|
|
|
|
mssql,
|
|
|
|
mysql,
|
2020-02-03 19:44:06 +00:00
|
|
|
postgres
|
|
|
|
};
|
2020-01-19 20:01:48 +00:00
|
|
|
|
|
|
|
function getDriver(connection) {
|
2020-02-03 19:34:38 +00:00
|
|
|
if (_.isString(connection)) {
|
|
|
|
return drivers[connection];
|
|
|
|
}
|
|
|
|
if (_.isPlainObject(connection)) {
|
|
|
|
const { engine } = connection;
|
|
|
|
if (engine) {
|
|
|
|
return drivers[engine];
|
|
|
|
}
|
|
|
|
}
|
2020-02-03 19:44:06 +00:00
|
|
|
throw new Error(`Cannot extract engine from ${connection}`);
|
2020-01-19 20:01:48 +00:00
|
|
|
}
|
|
|
|
module.exports = getDriver;
|