mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
feat: ds check
This commit is contained in:
@@ -8,6 +8,7 @@ from fastapi import APIRouter, File, UploadFile, HTTPException
|
||||
|
||||
from apps.db.engine import create_table, get_data_engine, insert_data
|
||||
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
|
||||
from ..crud.field import get_fields_by_table_id
|
||||
@@ -60,7 +61,11 @@ async def get_tables(session: SessionDep, id: int):
|
||||
|
||||
@router.post("/getTablesByConf")
|
||||
async def get_tables_by_conf(session: SessionDep, ds: CoreDatasource):
|
||||
return getTablesByDs(session, ds)
|
||||
try:
|
||||
return getTablesByDs(session, ds)
|
||||
except Exception as e:
|
||||
SQLBotLogUtil.error(f"get table failed: {e}")
|
||||
raise HTTPException(status_code=500, detail=f'Get table Failed: {e.args}')
|
||||
|
||||
|
||||
@router.post("/getFields/{id}/{table_name}")
|
||||
@@ -100,7 +105,11 @@ async def edit_field(session: SessionDep, field: CoreField):
|
||||
|
||||
@router.post("/previewData/{id}")
|
||||
async def edit_local(session: SessionDep, current_user: CurrentUser, id: int, data: TableObj):
|
||||
return preview(session, current_user, id, data)
|
||||
try:
|
||||
return preview(session, current_user, id, data)
|
||||
except Exception as e:
|
||||
SQLBotLogUtil.error(f"Preview failed: {e}")
|
||||
raise HTTPException(status_code=500, detail=f'Preview Failed: {e.args}')
|
||||
|
||||
|
||||
@router.post("/fieldEnum/{id}")
|
||||
|
||||
@@ -134,7 +134,7 @@ def getTables(session: SessionDep, id: int):
|
||||
|
||||
|
||||
def getTablesByDs(session: SessionDep, ds: CoreDatasource):
|
||||
check_status(session, ds, True)
|
||||
# check_status(session, ds, True)
|
||||
tables = get_tables(ds)
|
||||
return tables
|
||||
|
||||
@@ -241,7 +241,7 @@ def updateField(session: SessionDep, field: CoreField):
|
||||
|
||||
def preview(session: SessionDep, current_user: CurrentUser, id: int, data: TableObj):
|
||||
ds = session.query(CoreDatasource).filter(CoreDatasource.id == id).first()
|
||||
check_status(session, ds, True)
|
||||
# check_status(session, ds, True)
|
||||
|
||||
if data.fields is None or len(data.fields) == 0:
|
||||
return {"fields": [], "data": [], "sql": ''}
|
||||
|
||||
Reference in New Issue
Block a user