You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.8 KiB
78 lines
2.8 KiB
import { DATA_BASE_TYPES, DATA_BASE_TYPES_OTHER } from '@constants/constant'; |
|
import { CONSTANT_PLUGIN_TYPES, CONSTANT_PLUGIN_SHOW, CONSTANT_PLUGIN_EDIT } from '@constants/plugin'; |
|
import { DatabaseType } from './app.typings'; |
|
export function getAllDatabaseTypes():DatabaseType[] { |
|
return [ |
|
...DATA_BASE_TYPES, |
|
...BI.Constants.getConstant(CONSTANT_PLUGIN_TYPES).map(item => { |
|
return { |
|
...item, |
|
internal: false, |
|
commonly: false, |
|
}; |
|
}), |
|
]; |
|
} |
|
|
|
export function getPluginWidgetShow(plugin: string) { |
|
return BI.Constants.getConstant(CONSTANT_PLUGIN_SHOW.replace('${databaseType}', plugin)); |
|
} |
|
|
|
export function getPluginWidgetEdit(plugin: string) { |
|
return BI.Constants.getConstant(CONSTANT_PLUGIN_EDIT.replace('${databaseType}', plugin)); |
|
} |
|
|
|
// 由于database可能为空,所以为了兼容平台和设计器,需要根据driver来判断数据库类型 |
|
export function getJdbcDatabaseType(database: string, driver: string): DatabaseType { |
|
let databaseType = null; |
|
if (database && DATA_BASE_TYPES.some(item => item.databaseType === database)) { |
|
databaseType = DATA_BASE_TYPES.find(item => item.databaseType === database); |
|
} else { |
|
databaseType = (DATA_BASE_TYPES as DatabaseType[]).find(item => { |
|
if (item.drivers) { |
|
return item.drivers.includes(driver); |
|
} |
|
|
|
return item.driver === driver; |
|
}); |
|
} |
|
if (!databaseType) { |
|
return DATA_BASE_TYPES_OTHER; |
|
} |
|
|
|
return databaseType; |
|
} |
|
|
|
export function resolveUrlInfo (url: string) { |
|
if (BI.isNull(url)) return {}; |
|
const result = url.match(/^jdbc:(oracle|mysql|sqlserver|db2|impala|kylin|phoenix|derby|gbase|gbasedbt-sqli|informix-sqli|h2|postgresql|hive2|vertica|kingbase|presto):(thin:([0-9a-zA-Z/]*)?@|thin:([0-9a-zA-Z/]*)?@\/\/|\/\/|)([0-9a-zA-Z_\\.-]+)(:([0-9]+))?(:|\/|;DatabaseName=)([0-9a-zA-Z_\\.]+)(.*)/i); |
|
if (result) { |
|
return { |
|
host: result[5], |
|
port: result[7], |
|
databaseName: result[9], |
|
urlInfo: result[10], |
|
}; |
|
} |
|
|
|
// 处理oracle的RAC方式 |
|
if (/^jdbc:oracle:thin:([0-9a-zA-Z/]*)?@\(DESCRIPTION/i.test(url)) { |
|
const host = url.match(/\(HOST\s*=\s*([0-9a-zA-Z_\\.-]+)\)/i); |
|
const port = url.match(/\(PORT\s*=\s*([0-9]+)\)/i); |
|
const databaseName = url.match(/\(SERVICE_NAME\s*=\s*([\s0-9a-zA-Z_\\.]+)\)/i); |
|
|
|
return { |
|
host: host ? host[1] : '', |
|
port: port ? port[1] : '', |
|
databaseName: databaseName ? databaseName[1] : '', |
|
urlInfo: '', |
|
}; |
|
} |
|
|
|
return { |
|
host: '', |
|
port: '', |
|
databaseName: '', |
|
urlInfo: '', |
|
}; |
|
}
|
|
|