Skip to content

Commit a03a5c2

Browse files
committed
feat: support sql completion for table names
1 parent 0fe2afb commit a03a5c2

File tree

6 files changed

+60
-9
lines changed

6 files changed

+60
-9
lines changed

console/atest-ui/package-lock.json

Lines changed: 32 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

console/atest-ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"test": "vitest"
1717
},
1818
"dependencies": {
19+
"@codemirror/lang-sql": "github:codemirror/lang-sql",
1920
"@vueuse/core": "^10.11.0",
2021
"codemirror": "^5.65.17",
2122
"diff-match-patch": "^1.0.5",

console/atest-ui/src/assets/base.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
--page-title-right-padding: 10px;
4444
--page-title-bottom-padding: 5px;
45+
46+
--sql-editor-height: 180px;
4547
}
4648

4749
*,
@@ -99,3 +101,8 @@ html.dark .el-main {
99101
height: 32px;
100102
padding-bottom: var(--page-title-bottom-padding, 0px);
101103
}
104+
105+
.block-align-right {
106+
display: flex;
107+
justify-content: flex-end;
108+
}

console/atest-ui/src/locales/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"send": "Send",
1212
"copy": "Copy",
1313
"ok": "OK",
14+
"next-page": "Next",
1415
"reload": "Reload",
1516
"insertSample": "Insert Sample",
1617
"toolbox": "Tool Box",

console/atest-ui/src/locales/zh.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"send": "发送",
1212
"copy": "拷贝",
1313
"ok": "确定",
14+
"next-page": "下一页",
1415
"reload": "重新加载",
1516
"insertSample": "插入样例",
1617
"toolbox": "工具箱",

console/atest-ui/src/views/DataManager.vue

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { Pair } from './types'
77
import { GetDataManagerPreference, SetDataManagerPreference } from './cache'
88
import { ElMessage } from 'element-plus'
99
import { Codemirror } from 'vue-codemirror'
10+
import { sql, StandardSQL } from "@codemirror/lang-sql"
1011
import HistoryInput from '../components/HistoryInput.vue'
1112
import type { Ref } from 'vue'
1213
import { Refresh, Document } from '@element-plus/icons-vue'
@@ -176,7 +177,9 @@ const ormDataHandler = (data: QueryData) => {
176177
}
177178
178179
tablesTree.value = []
180+
sqlConfig.value.schema = {}
179181
queryDataMeta.value.tables.forEach((i) => {
182+
sqlConfig.value.schema[i] = []
180183
tablesTree.value.push({
181184
label: i,
182185
})
@@ -194,6 +197,13 @@ const keyValueDataHandler = (data: QueryData) => {
194197
})
195198
}
196199
200+
const sqlConfig = ref({
201+
dialect: StandardSQL,
202+
defaultSchema: queryDataMeta.value.currentDatabase,
203+
upperCaseKeywords: true,
204+
schema: {}
205+
})
206+
197207
const executeQuery = async () => {
198208
if (sqlQuery.value === '') {
199209
switch (kind.value) {
@@ -264,7 +274,7 @@ watch(largeContent, (e) => {
264274
})
265275
266276
Magic.AdvancedKeys([{
267-
Keys: ['Ctrl+E'],
277+
Keys: ['Ctrl+E', 'Ctrl+Enter'],
268278
Func: executeQuery,
269279
Description: 'Execute query'
270280
}])
@@ -342,11 +352,16 @@ Magic.AdvancedKeys([{
342352
</el-input>
343353
</el-col>
344354
<el-col :span="2">
345-
<el-button type="primary" @click="nextPage">Next</el-button>
355+
<el-button type="primary" @click="nextPage">{{ t("button.next-page") }}</el-button>
346356
</el-col>
347357
</el-row>
348358
</el-form>
349-
<Codemirror v-model="sqlQuery" v-if="complexEditor" style="height: 180px"/>
359+
<Codemirror
360+
v-model="sqlQuery"
361+
v-if="complexEditor"
362+
style="height: var(--sql-editor-height);"
363+
:extensions="[sql(sqlConfig)]"
364+
/>
350365
</el-header>
351366
<el-main>
352367
<div style="display: flex; gap: 8px;">

0 commit comments

Comments
 (0)