@@ -64,11 +64,16 @@ def get_engine(ds: CoreDatasource, timeout: int = 0) -> Engine:
6464 conf .timeout = timeout
6565 if timeout > 0 :
6666 conf .timeout = timeout
67- if ds .type == "pg" and (conf .dbSchema is not None and conf .dbSchema != "" ):
68- engine = create_engine (get_uri (ds ),
69- connect_args = {"options" : f"-c search_path={ urllib .parse .quote (conf .dbSchema )} " ,
70- "connect_timeout" : conf .timeout },
71- pool_timeout = conf .timeout )
67+ if ds .type == "pg" :
68+ if conf .dbSchema is not None and conf .dbSchema != "" :
69+ engine = create_engine (get_uri (ds ),
70+ connect_args = {"options" : f"-c search_path={ urllib .parse .quote (conf .dbSchema )} " ,
71+ "connect_timeout" : conf .timeout },
72+ pool_timeout = conf .timeout )
73+ else :
74+ engine = create_engine (get_uri (ds ),
75+ connect_args = {"connect_timeout" : conf .timeout },
76+ pool_timeout = conf .timeout )
7277 elif ds .type == 'sqlServer' :
7378 engine = create_engine (get_uri (ds ), pool_timeout = conf .timeout )
7479 elif ds .type == 'oracle' :
@@ -86,6 +91,32 @@ def get_session(ds: CoreDatasource | AssistantOutDsSchema):
8691 return session
8792
8893
94+ def get_schema (ds : CoreDatasource ):
95+ conf = DatasourceConf (** json .loads (aes_decrypt (ds .configuration ))) if ds .type != "excel" else get_engine_config ()
96+ db = DB .get_db (ds .type )
97+ if db .connect_type == ConnectType .sqlalchemy :
98+ with get_session (ds ) as session :
99+ sql : str = ''
100+ if ds .type == "sqlServer" :
101+ sql = f"""select name from sys.schemas"""
102+ elif ds .type == "pg" or ds .type == "excel" :
103+ sql = """SELECT nspname FROM pg_namespace"""
104+ elif ds .type == "oracle" :
105+ sql = f"""select * from all_users"""
106+ with session .execute (text (sql )) as result :
107+ res = result .fetchall ()
108+ res_list = [item [0 ] for item in res ]
109+ return res_list
110+ else :
111+ if ds .type == 'dm' :
112+ with dmPython .connect (user = conf .username , password = conf .password , server = conf .host ,
113+ port = conf .port ) as conn , conn .cursor () as cursor :
114+ cursor .execute (f"""select OBJECT_NAME from dba_objects where object_type='SCH'""" )
115+ res = cursor .fetchall ()
116+ res_list = [item [0 ] for item in res ]
117+ return res_list
118+
119+
89120def get_tables (ds : CoreDatasource ):
90121 conf = DatasourceConf (** json .loads (aes_decrypt (ds .configuration ))) if ds .type != "excel" else get_engine_config ()
91122 db = DB .get_db (ds .type )
0 commit comments