diff --git a/backend/apps/datasource/api/datasource.py b/backend/apps/datasource/api/datasource.py index d31fee92..e19a1278 100644 --- a/backend/apps/datasource/api/datasource.py +++ b/backend/apps/datasource/api/datasource.py @@ -30,7 +30,7 @@ async def get_datasource(session: SessionDep, id: int): @router.post("/check") async def check(session: SessionDep, ds: CoreDatasource): - return check_status(session, ds) + return check_status(session, ds, True) @router.post("/add", response_model=CoreDatasource) diff --git a/backend/apps/datasource/crud/datasource.py b/backend/apps/datasource/crud/datasource.py index 14f5b7ed..0960980b 100644 --- a/backend/apps/datasource/crud/datasource.py +++ b/backend/apps/datasource/crud/datasource.py @@ -35,14 +35,15 @@ def get_ds(session: SessionDep, id: int): return datasource -def check_status(session: SessionDep, ds: CoreDatasource): +def check_status(session: SessionDep, ds: CoreDatasource, is_raise: bool = False): conn = get_engine(ds) try: with conn.connect() as connection: print("success") return True except Exception as e: - raise HTTPException(status_code=500, detail=e.args) + if is_raise: + raise HTTPException(status_code=500, detail=f'Connect Failed: {e.args}') print("Fail:", e) return False diff --git a/backend/apps/db/db.py b/backend/apps/db/db.py index 46102cbd..b461d87e 100644 --- a/backend/apps/db/db.py +++ b/backend/apps/db/db.py @@ -126,7 +126,7 @@ def get_tables(ds: CoreDatasource): LEFT JOIN pg_description d ON d.objoid = c.oid AND d.objsubid = 0 WHERE n.nspname = current_schema() - AND c.relkind IN ('r', 'v') + AND c.relkind IN ('r', 'v', 'p') AND c.relname NOT LIKE 'pg_%' AND c.relname NOT LIKE 'sql_%' ORDER BY c.relname \ diff --git a/frontend/src/views/ds/Datasource.vue b/frontend/src/views/ds/Datasource.vue index 4dd39791..5d4a2360 100644 --- a/frontend/src/views/ds/Datasource.vue +++ b/frontend/src/views/ds/Datasource.vue @@ -95,12 +95,16 @@ const handleEditDatasource = (res: any) => { }) } -const handleQuestion = (id: string) => { - router.push({ - path: '/chat/index', - query: { - start_chat: id, - }, +const handleQuestion = (ele: any) => { + datasourceApi.check(ele).then((res: any) => { + if (res) { + router.push({ + path: '/chat/index', + query: { + start_chat: ele.id, + }, + }) + } }) } @@ -290,7 +294,7 @@ const back = () => { :type-name="ele.type_name" :num="ele.num" :description="ele.description" - @question="handleQuestion" + @question="handleQuestion(ele)" @edit="handleEditDatasource(ele)" @del="deleteHandler(ele)" @data-table-detail="dataTableDetail(ele)"