mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
fix: check ds status
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -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)"
|
||||
|
||||
Reference in New Issue
Block a user