Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion backend/apps/datasource/api/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
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
Expand Down Expand Up @@ -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


Expand Down
17 changes: 16 additions & 1 deletion backend/apps/datasource/crud/datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions frontend/src/api/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`),
}
3 changes: 2 additions & 1 deletion frontend/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@
},
"timeout": "Timeout(second)",
"address": "Address"
}
},
"sync_fields": "Sync Fields"
},
"datasource": {
"recommended_repetitive_tips": "Duplicate questions exist",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/i18n/ko-KR.json
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@
},
"timeout": "쿼리 시간 초과(초)",
"address": "주소"
}
},
"sync_fields": "동기화된 테이블 구조"
},
"datasource": {
"recommended_repetitive_tips": "중복된 문제가 존재합니다",
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@
},
"timeout": "查询超时(秒)",
"address": "地址"
}
},
"sync_fields": "同步表结构"
},
"datasource": {
"recommended_repetitive_tips": "存在重复问题",
Expand Down
39 changes: 31 additions & 8 deletions frontend/src/views/ds/DataTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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">
Expand All @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -804,7 +826,8 @@ const btnSelectClick = (val: any) => {
position: absolute;
right: 16px;
top: 16px;
width: 240px;
width: 360px;
display: flex;
}

.btn-select {
Expand Down