Skip to content

Commit a611289

Browse files
committed
feat: Add table field update functionality
1 parent 1ba4a7c commit a611289

File tree

7 files changed

+60
-13
lines changed

7 files changed

+60
-13
lines changed

backend/apps/datasource/api/datasource.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from common.utils.utils import SQLBotLogUtil
1818
from ..crud.datasource import get_datasource_list, check_status, create_ds, update_ds, delete_ds, getTables, getFields, \
1919
execSql, update_table_and_fields, getTablesByDs, chooseTables, preview, updateTable, updateField, get_ds, fieldEnum, \
20-
check_status_by_id
20+
check_status_by_id, sync_single_fields
2121
from ..crud.field import get_fields_by_table_id
2222
from ..crud.table import get_tables_by_ds_id
2323
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):
134134
return getFields(session, id, table_name)
135135

136136

137+
@router.post("/syncFields/{id}")
138+
async def sync_fields(session: SessionDep, id: int):
139+
return sync_single_fields(session, id)
140+
141+
137142
from pydantic import BaseModel
138143

139144

backend/apps/datasource/crud/datasource.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,14 @@ def update_ds(session: SessionDep, trans: Trans, user: CurrentUser, ds: CoreData
109109
run_save_ds_embeddings([ds.id])
110110
return ds
111111

112-
def update_ds_recommended_config(session: SessionDep,datasource_id: int, recommended_config:int):
112+
113+
def update_ds_recommended_config(session: SessionDep, datasource_id: int, recommended_config: int):
113114
record = session.exec(select(CoreDatasource).where(CoreDatasource.id == datasource_id)).first()
114115
record.recommended_config = recommended_config
115116
session.add(record)
116117
session.commit()
117118

119+
118120
def delete_ds(session: SessionDep, id: int):
119121
term = session.exec(select(CoreDatasource).where(CoreDatasource.id == id)).first()
120122
if term.type == "excel":
@@ -163,6 +165,19 @@ def execSql(session: SessionDep, id: int, sql: str):
163165
return exec_sql(ds, sql, True)
164166

165167

168+
def sync_single_fields(session: SessionDep, id: int):
169+
table = session.query(CoreTable).filter(CoreTable.id == id).first()
170+
ds = session.query(CoreDatasource).filter(CoreDatasource.id == table.ds_id).first()
171+
172+
# sync field
173+
fields = getFieldsByDs(session, ds, table.table_name)
174+
sync_fields(session, ds, table, fields)
175+
176+
# do table embedding
177+
run_save_table_embeddings([table.id])
178+
run_save_ds_embeddings([ds.id])
179+
180+
166181
def sync_table(session: SessionDep, ds: CoreDatasource, tables: List[CoreTable]):
167182
id_list = []
168183
for item in tables:

frontend/src/api/datasource.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ export const datasourceApi = {
2626
getDs: (id: number) => request.post(`/datasource/get/${id}`),
2727
cancelRequests: () => request.cancelRequests(),
2828
getSchema: (data: any) => request.post('/datasource/getSchemaByConf', data),
29+
syncFields: (id: number) => request.post(`/datasource/syncFields/${id}`),
2930
}

frontend/src/i18n/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@
335335
},
336336
"timeout": "Timeout(second)",
337337
"address": "Address"
338-
}
338+
},
339+
"sync_fields": "Sync Fields"
339340
},
340341
"datasource": {
341342
"recommended_repetitive_tips": "Duplicate questions exist",

frontend/src/i18n/ko-KR.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,8 @@
335335
},
336336
"timeout": "쿼리 시간 초과(초)",
337337
"address": "주소"
338-
}
338+
},
339+
"sync_fields": "동기화된 테이블 구조"
339340
},
340341
"datasource": {
341342
"recommended_repetitive_tips": "중복된 문제가 존재합니다",

frontend/src/i18n/zh-CN.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,8 @@
336336
},
337337
"timeout": "查询超时(秒)",
338338
"address": "地址"
339-
}
339+
},
340+
"sync_fields": "同步表结构"
340341
},
341342
"datasource": {
342343
"recommended_repetitive_tips": "存在重复问题",

frontend/src/views/ds/DataTable.vue

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useI18n } from 'vue-i18n'
1010
import ParamsForm from './ParamsForm.vue'
1111
import TableRelationship from '@/views/ds/TableRelationship.vue'
1212
import icon_mindnote_outlined from '@/assets/svg/icon_mindnote_outlined.svg'
13+
import { Refresh } from '@element-plus/icons-vue'
1314
interface Table {
1415
name: string
1516
host: string
@@ -223,6 +224,19 @@ const changeStatus = (row: any) => {
223224
})
224225
}
225226
227+
const syncFields = () => {
228+
loading.value = true
229+
datasourceApi
230+
.syncFields(currentTable.value.id)
231+
.then(() => {
232+
btnSelectClick('d')
233+
loading.value = false
234+
})
235+
.catch(() => {
236+
loading.value = false
237+
})
238+
}
239+
226240
const emits = defineEmits(['back', 'refresh'])
227241
const back = () => {
228242
emits('back')
@@ -316,13 +330,13 @@ const btnSelectClick = (val: any) => {
316330
:key="ele.table_name"
317331
:draggable="activeRelationship && !tableName.includes(ele.id)"
318332
class="model"
319-
@dragstart="($event: any) => singleDragStartD($event, ele)"
320-
@dragend="singleDragEnd"
321333
:class="[
322334
currentTable.table_name === ele.table_name && 'isActive',
323335
tableName.includes(ele.id) && activeRelationship && 'disabled-table',
324336
]"
325337
:title="ele.table_name"
338+
@dragstart="($event: any) => singleDragStartD($event, ele)"
339+
@dragend="singleDragEnd"
326340
@click="clickTable(ele)"
327341
>
328342
<el-icon size="16">
@@ -349,7 +363,7 @@ const btnSelectClick = (val: any) => {
349363
</div>
350364
</div>
351365
<div class="table-relationship">
352-
<div @click="handleRelationship" :class="activeRelationship && 'active'" class="btn">
366+
<div :class="activeRelationship && 'active'" class="btn" @click="handleRelationship">
353367
<el-icon size="16">
354368
<icon_mindnote_outlined></icon_mindnote_outlined>
355369
</el-icon>
@@ -362,9 +376,9 @@ const btnSelectClick = (val: any) => {
362376
<div class="title">{{ t('training.table_relationship_management') }}</div>
363377
<div class="content">
364378
<TableRelationship
365-
@getTableName="getTableName"
366-
:dragging="isDrag"
367379
:id="info.id"
380+
:dragging="isDrag"
381+
@get-table-name="getTableName"
368382
></TableRelationship>
369383
</div>
370384
</div>
@@ -409,12 +423,20 @@ const btnSelectClick = (val: any) => {
409423
</div>
410424
<div v-if="btnSelect === 'd'" class="field-name">
411425
<el-input
412-
:placeholder="t('dashboard.search')"
413426
v-model="fieldName"
414-
@blur="fieldNameSearch"
427+
:placeholder="t('dashboard.search')"
415428
autocomplete="off"
416429
clearable
430+
@blur="fieldNameSearch"
417431
/>
432+
<el-button
433+
v-if="ds.type !== 'excel'"
434+
:icon="Refresh"
435+
style="margin-left: 12px"
436+
@click="syncFields()"
437+
>
438+
{{ t('ds.sync_fields') }}
439+
</el-button>
418440
</div>
419441

420442
<div
@@ -804,7 +826,8 @@ const btnSelectClick = (val: any) => {
804826
position: absolute;
805827
right: 16px;
806828
top: 16px;
807-
width: 240px;
829+
width: 360px;
830+
display: flex;
808831
}
809832
810833
.btn-select {

0 commit comments

Comments
 (0)