Skip to content

Commit 5654c73

Browse files
committed
Merge branch 'main' of https://github.com/dataease/SQLBot
2 parents 898b402 + 4fe96ad commit 5654c73

File tree

5 files changed

+38
-5
lines changed

5 files changed

+38
-5
lines changed

backend/apps/datasource/api/datasource.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from common.core.deps import SessionDep, CurrentUser, Trans
1313
from common.utils.utils import SQLBotLogUtil
1414
from ..crud.datasource import get_datasource_list, check_status, create_ds, update_ds, delete_ds, getTables, getFields, \
15-
execSql, update_table_and_fields, getTablesByDs, chooseTables, preview, updateTable, updateField, get_ds, fieldEnum
15+
execSql, update_table_and_fields, getTablesByDs, chooseTables, preview, updateTable, updateField, get_ds, fieldEnum, \
16+
check_status_by_id
1617
from ..crud.field import get_fields_by_table_id
1718
from ..crud.table import get_tables_by_ds_id
1819
from ..models.datasource import CoreDatasource, CreateDatasource, TableObj, CoreTable, CoreField
@@ -46,6 +47,14 @@ def inner():
4647
return await asyncio.to_thread(inner)
4748

4849

50+
@router.get("/check/{ds_id}")
51+
async def check_by_id(session: SessionDep, trans: Trans, ds_id: int):
52+
def inner():
53+
return check_status_by_id(session, trans, ds_id, True)
54+
55+
return await asyncio.to_thread(inner)
56+
57+
4958
@router.post("/add", response_model=CoreDatasource)
5059
async def add(session: SessionDep, trans: Trans, user: CurrentUser, ds: CreateDatasource):
5160
def inner():

backend/apps/datasource/crud/datasource.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from typing import List, Optional
44

55
from fastapi import HTTPException
6-
from sqlalchemy import and_, text, func
6+
from sqlalchemy import and_, text
77
from sqlmodel import select
88

99
from apps.datasource.crud.permission import get_column_permission_fields, get_row_permission_filters, is_normal_user
@@ -35,6 +35,15 @@ def get_ds(session: SessionDep, id: int):
3535
return datasource
3636

3737

38+
def check_status_by_id(session: SessionDep, trans: Trans, ds_id: int, is_raise: bool = False):
39+
ds = session.get(CoreDatasource, ds_id)
40+
if ds is None:
41+
if is_raise:
42+
raise HTTPException(status_code=500, detail=trans('i18n_ds_invalid'))
43+
return False
44+
return check_status(session, trans, ds, is_raise)
45+
46+
3847
def check_status(session: SessionDep, trans: Trans, ds: CoreDatasource, is_raise: bool = False):
3948
conn = get_engine(ds, 10)
4049
try:

frontend/src/api/datasource.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { request } from '@/utils/request'
22

33
export const datasourceApi = {
44
check: (data: any) => request.post('/datasource/check', data),
5+
check_by_id: (id: any) => request.get(`/datasource/check/${id}`),
56
add: (data: any) => request.post('/datasource/add', data),
67
list: () => request.get('/datasource/list'),
78
update: (data: any) => request.post('/datasource/update', data),

frontend/src/views/chat/ChatCreator.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,12 @@ function selectDsInDialog(ds: any) {
6868
6969
function confirmSelectDs() {
7070
if (innerDs.value) {
71-
createChat(innerDs.value)
71+
//check first
72+
datasourceApi.check_by_id(innerDs.value).then((res: any) => {
73+
if (res) {
74+
createChat(innerDs.value)
75+
}
76+
})
7277
}
7378
}
7479

frontend/src/views/ds/Card.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ import icon_more_outlined from '@/assets/svg/icon_more_outlined.svg'
44
import icon_form_outlined from '@/assets/svg/icon_form_outlined.svg'
55
import icon_chat_outlined from '@/assets/svg/icon_chat_outlined.svg'
66
import { ref, unref, computed } from 'vue'
7-
import { ClickOutside as vClickOutside } from 'element-plus-secondary'
7+
import { ClickOutside as vClickOutside, ElMessage } from 'element-plus-secondary'
88
import { dsTypeWithImg } from './js/ds-type'
99
import edit from '@/assets/svg/icon_edit_outlined.svg'
10+
import { datasourceApi } from '@/api/datasource.ts'
11+
import { encrypted } from '@/views/ds/js/aes.ts'
12+
import { useI18n } from 'vue-i18n'
13+
const { t } = useI18n()
1014
1115
const props = withDefaults(
1216
defineProps<{
@@ -39,7 +43,12 @@ const handleDel = () => {
3943
}
4044
4145
const handleQuestion = () => {
42-
emits('question', props.id)
46+
//check first
47+
datasourceApi.check_by_id(props.id).then((res: any) => {
48+
if (res) {
49+
emits('question', props.id)
50+
}
51+
})
4352
}
4453
4554
const dataTableDetail = () => {

0 commit comments

Comments
 (0)