Browse Source

fix: 更新数据连接解析

research/10.0
alan 5 years ago
parent
commit
598a7520c6
  1. 15
      src/modules/__test__/app.test.ts
  2. 16
      src/modules/app.service.ts

15
src/modules/__test__/app.test.ts

@ -52,6 +52,21 @@ test('解析url', () => {
databaseName: 'database',
urlInfo: '',
});
expect(resolveUrlInfo('jdbc:sqlserver://hostname:port;databaseName=database')).toEqual({
host: 'hostname',
port: '',
databaseName: 'database',
urlInfo: '',
});
});
test('数据库可能为空', () => {
expect(resolveUrlInfo('jdbc:mysql://secure.finedevelop.com:62306/')).toEqual({
host: 'secure.finedevelop.com',
port: '62306',
databaseName: '',
urlInfo: '',
});
});
/**

16
src/modules/app.service.ts

@ -49,7 +49,17 @@ export function getJdbcDatabaseType(database: string, driver: string): DatabaseT
export function resolveUrlInfo (url: string) {
if (BI.isNull(url)) return {};
const greenplumUrl = url.match(/^jdbc:(pivotal:greenplum):(thin:([0-9a-zA-Z/]*)?@\/\/|\/\/|)([0-9a-zA-Z_\\.-]+)(:([0-9|port]+))?(:|\/|;)([^]+)(.*)/i);
const oracleUlr = url.match(/^jdbc:(oracle):(thin:([0-9a-zA-Z/]*)?@|thin:([0-9a-zA-Z/]*)?@\/\/|\/\/|)([0-9a-zA-Z_\\.-]+)(:([0-9|port]+))?(:)([^]+)(.*)/i);
if (oracleUlr) {
return {
host: oracleUlr[5],
port: oracleUlr[7] === 'port' ? '' : oracleUlr[7],
databaseName: oracleUlr[9],
urlInfo: oracleUlr[10],
};
}
const greenplumUrl = url.match(/^jdbc:(pivotal:greenplum):(thin:([0-9a-zA-Z/]*)?@\/\/|\/\/|)([0-9a-zA-Z_\\.-]+)(:([0-9|port]+))?(\/|;)([^]+)(.*)/i);
if (greenplumUrl) {
return {
host: greenplumUrl[4],
@ -58,12 +68,12 @@ export function resolveUrlInfo (url: string) {
urlInfo: greenplumUrl[9],
};
}
const result = url.match(/^jdbc:(oracle|mysql|sqlserver|db2|impala|kylin|phoenix|derby|gbase|gbasedbt-sqli|informix-sqli|h2|postgresql|hive2|vertica|kingbase|presto|redshift|postgresql):(thin:([0-9a-zA-Z/]*)?@|thin:([0-9a-zA-Z/]*)?@\/\/|\/\/|)([0-9a-zA-Z_\\.-]+)(:([0-9|port]+))?(:|\/|;DatabaseName=)([^]+)(.*)/i);
const result = url.match(/^jdbc:(mysql|sqlserver|db2|impala|kylin|phoenix|derby|gbase|gbasedbt-sqli|informix-sqli|h2|postgresql|hive2|vertica|kingbase|presto|redshift|postgresql):(thin:([0-9a-zA-Z/]*)?@|thin:([0-9a-zA-Z/]*)?@\/\/|\/\/|)([0-9a-zA-Z_\\.-]+)(:([0-9|port]+))?(\/|;DatabaseName=)?([^]+)?(.*)/i);
if (result) {
return {
host: result[5],
port: result[7] === 'port' ? '' : result[7],
databaseName: result[9],
databaseName: result[9] || '',
urlInfo: result[10],
};
}

Loading…
Cancel
Save