(type: str, conf: DatasourceConf)
| 57 | |
| 58 | |
| 59 | def get_uri_from_config(type: str, conf: DatasourceConf) -> str: |
| 60 | db_url: str |
| 61 | if equals_ignore_case(type, "mysql"): |
| 62 | checkParams(conf.extraJdbc, DB.mysql.illegalParams) |
| 63 | if conf.extraJdbc is not None and conf.extraJdbc != '': |
| 64 | db_url = f"mysql+pymysql://{urllib.parse.quote(conf.username)}:{urllib.parse.quote(conf.password)}@{conf.host}:{conf.port}/{conf.database}?{conf.extraJdbc}" |
| 65 | else: |
| 66 | db_url = f"mysql+pymysql://{urllib.parse.quote(conf.username)}:{urllib.parse.quote(conf.password)}@{conf.host}:{conf.port}/{conf.database}" |
| 67 | elif equals_ignore_case(type, "sqlServer"): |
| 68 | if conf.extraJdbc is not None and conf.extraJdbc != '': |
| 69 | db_url = f"mssql+pymssql://{urllib.parse.quote(conf.username)}:{urllib.parse.quote(conf.password)}@{conf.host}:{conf.port}/{conf.database}?{conf.extraJdbc}" |
| 70 | else: |
| 71 | db_url = f"mssql+pymssql://{urllib.parse.quote(conf.username)}:{urllib.parse.quote(conf.password)}@{conf.host}:{conf.port}/{conf.database}" |
| 72 | elif equals_ignore_case(type, "pg", "excel"): |
| 73 | if conf.extraJdbc is not None and conf.extraJdbc != '': |
| 74 | db_url = f"postgresql+psycopg2://{urllib.parse.quote(conf.username)}:{urllib.parse.quote(conf.password)}@{conf.host}:{conf.port}/{conf.database}?{conf.extraJdbc}" |
| 75 | else: |
| 76 | db_url = f"postgresql+psycopg2://{urllib.parse.quote(conf.username)}:{urllib.parse.quote(conf.password)}@{conf.host}:{conf.port}/{conf.database}" |
| 77 | elif equals_ignore_case(type, "oracle"): |
| 78 | if equals_ignore_case(conf.mode, "service_name", "serviceName"): |
| 79 | if conf.extraJdbc is not None and conf.extraJdbc != '': |
| 80 | db_url = f"oracle+oracledb://{urllib.parse.quote(conf.username)}:{urllib.parse.quote(conf.password)}@{conf.host}:{conf.port}?service_name={conf.database}&{conf.extraJdbc}" |
| 81 | else: |
| 82 | db_url = f"oracle+oracledb://{urllib.parse.quote(conf.username)}:{urllib.parse.quote(conf.password)}@{conf.host}:{conf.port}?service_name={conf.database}" |
| 83 | else: |
| 84 | if conf.extraJdbc is not None and conf.extraJdbc != '': |
| 85 | db_url = f"oracle+oracledb://{urllib.parse.quote(conf.username)}:{urllib.parse.quote(conf.password)}@{conf.host}:{conf.port}/{conf.database}?{conf.extraJdbc}" |
| 86 | else: |
| 87 | db_url = f"oracle+oracledb://{urllib.parse.quote(conf.username)}:{urllib.parse.quote(conf.password)}@{conf.host}:{conf.port}/{conf.database}" |
| 88 | elif equals_ignore_case(type, "ck"): |
| 89 | if conf.extraJdbc is not None and conf.extraJdbc != '': |
| 90 | db_url = f"clickhouse+http://{urllib.parse.quote(conf.username)}:{urllib.parse.quote(conf.password)}@{conf.host}:{conf.port}/{conf.database}?{conf.extraJdbc}" |
| 91 | else: |
| 92 | db_url = f"clickhouse+http://{urllib.parse.quote(conf.username)}:{urllib.parse.quote(conf.password)}@{conf.host}:{conf.port}/{conf.database}" |
| 93 | else: |
| 94 | raise 'The datasource type not support.' |
| 95 | return db_url |
| 96 | |
| 97 | |
| 98 | def get_extra_config(conf: DatasourceConf): |
no test coverage detected