MCPcopy Index your code
hub / github.com/dataease/SQLBot / get_uri_from_config

Function get_uri_from_config

backend/apps/db/db.py:59–95  ·  view source on GitHub ↗
(type: str, conf: DatasourceConf)

Source from the content-addressed store, hash-verified

57
58
59def 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
98def get_extra_config(conf: DatasourceConf):

Callers 1

get_uriFunction · 0.85

Calls 2

equals_ignore_caseFunction · 0.90
checkParamsFunction · 0.85

Tested by

no test coverage detected