mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
feat: Add table field update functionality
This commit is contained in:
@@ -17,7 +17,7 @@ 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, \
|
||||
check_status_by_id
|
||||
check_status_by_id, sync_single_fields
|
||||
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, FieldObj
|
||||
@@ -134,6 +134,11 @@ async def get_fields(session: SessionDep, id: int, table_name: str):
|
||||
return getFields(session, id, table_name)
|
||||
|
||||
|
||||
@router.post("/syncFields/{id}")
|
||||
async def sync_fields(session: SessionDep, id: int):
|
||||
return sync_single_fields(session, id)
|
||||
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
|
||||
@@ -109,12 +109,14 @@ def update_ds(session: SessionDep, trans: Trans, user: CurrentUser, ds: CoreData
|
||||
run_save_ds_embeddings([ds.id])
|
||||
return ds
|
||||
|
||||
def update_ds_recommended_config(session: SessionDep,datasource_id: int, recommended_config:int):
|
||||
|
||||
def update_ds_recommended_config(session: SessionDep, datasource_id: int, recommended_config: int):
|
||||
record = session.exec(select(CoreDatasource).where(CoreDatasource.id == datasource_id)).first()
|
||||
record.recommended_config = recommended_config
|
||||
session.add(record)
|
||||
session.commit()
|
||||
|
||||
|
||||
def delete_ds(session: SessionDep, id: int):
|
||||
term = session.exec(select(CoreDatasource).where(CoreDatasource.id == id)).first()
|
||||
if term.type == "excel":
|
||||
@@ -163,6 +165,19 @@ def execSql(session: SessionDep, id: int, sql: str):
|
||||
return exec_sql(ds, sql, True)
|
||||
|
||||
|
||||
def sync_single_fields(session: SessionDep, id: int):
|
||||
table = session.query(CoreTable).filter(CoreTable.id == id).first()
|
||||
ds = session.query(CoreDatasource).filter(CoreDatasource.id == table.ds_id).first()
|
||||
|
||||
# sync field
|
||||
fields = getFieldsByDs(session, ds, table.table_name)
|
||||
sync_fields(session, ds, table, fields)
|
||||
|
||||
# do table embedding
|
||||
run_save_table_embeddings([table.id])
|
||||
run_save_ds_embeddings([ds.id])
|
||||
|
||||
|
||||
def sync_table(session: SessionDep, ds: CoreDatasource, tables: List[CoreTable]):
|
||||
id_list = []
|
||||
for item in tables:
|
||||
|
||||
@@ -26,4 +26,5 @@ export const datasourceApi = {
|
||||
getDs: (id: number) => request.post(`/datasource/get/${id}`),
|
||||
cancelRequests: () => request.cancelRequests(),
|
||||
getSchema: (data: any) => request.post('/datasource/getSchemaByConf', data),
|
||||
syncFields: (id: number) => request.post(`/datasource/syncFields/${id}`),
|
||||
}
|
||||
|
||||
@@ -335,7 +335,8 @@
|
||||
},
|
||||
"timeout": "Timeout(second)",
|
||||
"address": "Address"
|
||||
}
|
||||
},
|
||||
"sync_fields": "Sync Fields"
|
||||
},
|
||||
"datasource": {
|
||||
"recommended_repetitive_tips": "Duplicate questions exist",
|
||||
|
||||
@@ -335,7 +335,8 @@
|
||||
},
|
||||
"timeout": "쿼리 시간 초과(초)",
|
||||
"address": "주소"
|
||||
}
|
||||
},
|
||||
"sync_fields": "동기화된 테이블 구조"
|
||||
},
|
||||
"datasource": {
|
||||
"recommended_repetitive_tips": "중복된 문제가 존재합니다",
|
||||
|
||||
@@ -336,7 +336,8 @@
|
||||
},
|
||||
"timeout": "查询超时(秒)",
|
||||
"address": "地址"
|
||||
}
|
||||
},
|
||||
"sync_fields": "同步表结构"
|
||||
},
|
||||
"datasource": {
|
||||
"recommended_repetitive_tips": "存在重复问题",
|
||||
|
||||
@@ -10,6 +10,7 @@ import { useI18n } from 'vue-i18n'
|
||||
import ParamsForm from './ParamsForm.vue'
|
||||
import TableRelationship from '@/views/ds/TableRelationship.vue'
|
||||
import icon_mindnote_outlined from '@/assets/svg/icon_mindnote_outlined.svg'
|
||||
import { Refresh } from '@element-plus/icons-vue'
|
||||
interface Table {
|
||||
name: string
|
||||
host: string
|
||||
@@ -223,6 +224,19 @@ const changeStatus = (row: any) => {
|
||||
})
|
||||
}
|
||||
|
||||
const syncFields = () => {
|
||||
loading.value = true
|
||||
datasourceApi
|
||||
.syncFields(currentTable.value.id)
|
||||
.then(() => {
|
||||
btnSelectClick('d')
|
||||
loading.value = false
|
||||
})
|
||||
.catch(() => {
|
||||
loading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
const emits = defineEmits(['back', 'refresh'])
|
||||
const back = () => {
|
||||
emits('back')
|
||||
@@ -316,13 +330,13 @@ const btnSelectClick = (val: any) => {
|
||||
:key="ele.table_name"
|
||||
:draggable="activeRelationship && !tableName.includes(ele.id)"
|
||||
class="model"
|
||||
@dragstart="($event: any) => singleDragStartD($event, ele)"
|
||||
@dragend="singleDragEnd"
|
||||
:class="[
|
||||
currentTable.table_name === ele.table_name && 'isActive',
|
||||
tableName.includes(ele.id) && activeRelationship && 'disabled-table',
|
||||
]"
|
||||
:title="ele.table_name"
|
||||
@dragstart="($event: any) => singleDragStartD($event, ele)"
|
||||
@dragend="singleDragEnd"
|
||||
@click="clickTable(ele)"
|
||||
>
|
||||
<el-icon size="16">
|
||||
@@ -349,7 +363,7 @@ const btnSelectClick = (val: any) => {
|
||||
</div>
|
||||
</div>
|
||||
<div class="table-relationship">
|
||||
<div @click="handleRelationship" :class="activeRelationship && 'active'" class="btn">
|
||||
<div :class="activeRelationship && 'active'" class="btn" @click="handleRelationship">
|
||||
<el-icon size="16">
|
||||
<icon_mindnote_outlined></icon_mindnote_outlined>
|
||||
</el-icon>
|
||||
@@ -362,9 +376,9 @@ const btnSelectClick = (val: any) => {
|
||||
<div class="title">{{ t('training.table_relationship_management') }}</div>
|
||||
<div class="content">
|
||||
<TableRelationship
|
||||
@getTableName="getTableName"
|
||||
:dragging="isDrag"
|
||||
:id="info.id"
|
||||
:dragging="isDrag"
|
||||
@get-table-name="getTableName"
|
||||
></TableRelationship>
|
||||
</div>
|
||||
</div>
|
||||
@@ -409,12 +423,20 @@ const btnSelectClick = (val: any) => {
|
||||
</div>
|
||||
<div v-if="btnSelect === 'd'" class="field-name">
|
||||
<el-input
|
||||
:placeholder="t('dashboard.search')"
|
||||
v-model="fieldName"
|
||||
@blur="fieldNameSearch"
|
||||
:placeholder="t('dashboard.search')"
|
||||
autocomplete="off"
|
||||
clearable
|
||||
@blur="fieldNameSearch"
|
||||
/>
|
||||
<el-button
|
||||
v-if="ds.type !== 'excel'"
|
||||
:icon="Refresh"
|
||||
style="margin-left: 12px"
|
||||
@click="syncFields()"
|
||||
>
|
||||
{{ t('ds.sync_fields') }}
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
@@ -804,7 +826,8 @@ const btnSelectClick = (val: any) => {
|
||||
position: absolute;
|
||||
right: 16px;
|
||||
top: 16px;
|
||||
width: 240px;
|
||||
width: 360px;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.btn-select {
|
||||
|
||||
Reference in New Issue
Block a user