mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 17:26:55 +08:00
feat: Add table field update functionality
This commit is contained in:
@@ -158,8 +158,9 @@ async def get_fields(session: SessionDep,
|
||||
|
||||
|
||||
@router.post("/syncFields/{id}", response_model=None, summary=f"{PLACEHOLDER_PREFIX}ds_sync_fields")
|
||||
async def sync_fields(session: SessionDep, id: int = Path(..., description=f"{PLACEHOLDER_PREFIX}ds_table_id")):
|
||||
return sync_single_fields(session, id)
|
||||
async def sync_fields(session: SessionDep, trans: Trans,
|
||||
id: int = Path(..., description=f"{PLACEHOLDER_PREFIX}ds_table_id")):
|
||||
return sync_single_fields(session, trans, id)
|
||||
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
@@ -165,10 +165,18 @@ def execSql(session: SessionDep, id: int, sql: str):
|
||||
return exec_sql(ds, sql, True)
|
||||
|
||||
|
||||
def sync_single_fields(session: SessionDep, id: int):
|
||||
def sync_single_fields(session: SessionDep, trans: Trans, id: int):
|
||||
table = session.query(CoreTable).filter(CoreTable.id == id).first()
|
||||
ds = session.query(CoreDatasource).filter(CoreDatasource.id == table.ds_id).first()
|
||||
|
||||
tables = getTablesByDs(session, ds)
|
||||
t_name = []
|
||||
for _t in tables:
|
||||
t_name.append(_t.tableName)
|
||||
|
||||
if not table.table_name in t_name:
|
||||
raise HTTPException(status_code=500, detail=trans('i18n_table_not_exist'))
|
||||
|
||||
# sync field
|
||||
fields = getFieldsByDs(session, ds, table.table_name)
|
||||
sync_fields(session, ds, table, fields)
|
||||
|
||||
@@ -174,5 +174,6 @@
|
||||
"params_setting": "Parameters Setting",
|
||||
"rules": "Permission Rules",
|
||||
"log_setting": "Login Authentication"
|
||||
}
|
||||
},
|
||||
"i18n_table_not_exist": "Table not exist"
|
||||
}
|
||||
@@ -174,5 +174,6 @@
|
||||
"params_setting": "매개변수 설정",
|
||||
"rules": "권한 규칙",
|
||||
"log_setting": "로그인 인증"
|
||||
}
|
||||
},
|
||||
"i18n_table_not_exist": "현재 테이블이 존재하지 않습니다"
|
||||
}
|
||||
@@ -174,5 +174,6 @@
|
||||
"params_setting": "参数设置",
|
||||
"rules": "权限规则",
|
||||
"log_setting": "登录认证"
|
||||
}
|
||||
},
|
||||
"i18n_table_not_exist": "当前表不存在"
|
||||
}
|
||||
Reference in New Issue
Block a user