mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
Merge branch 'main' of https://github.com/dataease/SQLBot
This commit is contained in:
@@ -12,7 +12,8 @@ from common.core.config import settings
|
||||
from common.core.deps import SessionDep, CurrentUser, Trans
|
||||
from common.utils.utils import SQLBotLogUtil
|
||||
from ..crud.datasource import get_datasource_list, check_status, create_ds, update_ds, delete_ds, getTables, getFields, \
|
||||
execSql, update_table_and_fields, getTablesByDs, chooseTables, preview, updateTable, updateField, get_ds, fieldEnum
|
||||
execSql, update_table_and_fields, getTablesByDs, chooseTables, preview, updateTable, updateField, get_ds, fieldEnum, \
|
||||
check_status_by_id
|
||||
from ..crud.field import get_fields_by_table_id
|
||||
from ..crud.table import get_tables_by_ds_id
|
||||
from ..models.datasource import CoreDatasource, CreateDatasource, TableObj, CoreTable, CoreField
|
||||
@@ -46,6 +47,14 @@ async def check(session: SessionDep, trans: Trans, ds: CoreDatasource):
|
||||
return await asyncio.to_thread(inner)
|
||||
|
||||
|
||||
@router.get("/check/{ds_id}")
|
||||
async def check_by_id(session: SessionDep, trans: Trans, ds_id: int):
|
||||
def inner():
|
||||
return check_status_by_id(session, trans, ds_id, True)
|
||||
|
||||
return await asyncio.to_thread(inner)
|
||||
|
||||
|
||||
@router.post("/add", response_model=CoreDatasource)
|
||||
async def add(session: SessionDep, trans: Trans, user: CurrentUser, ds: CreateDatasource):
|
||||
def inner():
|
||||
|
||||
@@ -3,7 +3,7 @@ import json
|
||||
from typing import List, Optional
|
||||
|
||||
from fastapi import HTTPException
|
||||
from sqlalchemy import and_, text, func
|
||||
from sqlalchemy import and_, text
|
||||
from sqlmodel import select
|
||||
|
||||
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):
|
||||
return datasource
|
||||
|
||||
|
||||
def check_status_by_id(session: SessionDep, trans: Trans, ds_id: int, is_raise: bool = False):
|
||||
ds = session.get(CoreDatasource, ds_id)
|
||||
if ds is None:
|
||||
if is_raise:
|
||||
raise HTTPException(status_code=500, detail=trans('i18n_ds_invalid'))
|
||||
return False
|
||||
return check_status(session, trans, ds, is_raise)
|
||||
|
||||
|
||||
def check_status(session: SessionDep, trans: Trans, ds: CoreDatasource, is_raise: bool = False):
|
||||
conn = get_engine(ds, 10)
|
||||
try:
|
||||
|
||||
@@ -2,6 +2,7 @@ import { request } from '@/utils/request'
|
||||
|
||||
export const datasourceApi = {
|
||||
check: (data: any) => request.post('/datasource/check', data),
|
||||
check_by_id: (id: any) => request.get(`/datasource/check/${id}`),
|
||||
add: (data: any) => request.post('/datasource/add', data),
|
||||
list: () => request.get('/datasource/list'),
|
||||
update: (data: any) => request.post('/datasource/update', data),
|
||||
|
||||
@@ -68,7 +68,12 @@ function selectDsInDialog(ds: any) {
|
||||
|
||||
function confirmSelectDs() {
|
||||
if (innerDs.value) {
|
||||
createChat(innerDs.value)
|
||||
//check first
|
||||
datasourceApi.check_by_id(innerDs.value).then((res: any) => {
|
||||
if (res) {
|
||||
createChat(innerDs.value)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,13 @@ import icon_more_outlined from '@/assets/svg/icon_more_outlined.svg'
|
||||
import icon_form_outlined from '@/assets/svg/icon_form_outlined.svg'
|
||||
import icon_chat_outlined from '@/assets/svg/icon_chat_outlined.svg'
|
||||
import { ref, unref, computed } from 'vue'
|
||||
import { ClickOutside as vClickOutside } from 'element-plus-secondary'
|
||||
import { ClickOutside as vClickOutside, ElMessage } from 'element-plus-secondary'
|
||||
import { dsTypeWithImg } from './js/ds-type'
|
||||
import edit from '@/assets/svg/icon_edit_outlined.svg'
|
||||
import { datasourceApi } from '@/api/datasource.ts'
|
||||
import { encrypted } from '@/views/ds/js/aes.ts'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
const { t } = useI18n()
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
@@ -39,7 +43,12 @@ const handleDel = () => {
|
||||
}
|
||||
|
||||
const handleQuestion = () => {
|
||||
emits('question', props.id)
|
||||
//check first
|
||||
datasourceApi.check_by_id(props.id).then((res: any) => {
|
||||
if (res) {
|
||||
emits('question', props.id)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const dataTableDetail = () => {
|
||||
|
||||
Reference in New Issue
Block a user