Skip to content

Commit b687b06

Browse files
committed
support to choose mysql database
1 parent 2f9f9b5 commit b687b06

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,24 @@ import { API } from './net'
44
import { Cache } from './cache'
55
import { ElMessage } from 'element-plus'
66
7+
const stores = ref([])
8+
const store = ref('')
79
const sqlQuery = ref('select * from t_sys_global_config')
810
const queryResult = ref([])
911
const columns = ref([])
1012
11-
const executeQuery = async () => {
12-
Cache.SetCurrentStore('mysql');
13+
API.GetStores((data) => {
14+
stores.value = data.data
15+
}, (e) => {
16+
ElMessage({
17+
showClose: true,
18+
message: e.message,
19+
type: 'error'
20+
});
21+
})
1322
14-
API.DataQuery(sqlQuery.value, (data) => {
23+
const executeQuery = async () => {
24+
API.DataQuery(store.value, sqlQuery.value, (data) => {
1525
const result = []
1626
const cols = new Set()
1727
@@ -25,7 +35,11 @@ const executeQuery = async () => {
2535
})
2636
2737
queryResult.value = result
28-
columns.value = Array.from(cols)
38+
columns.value = Array.from(cols).sort((a, b) => {
39+
if (a === 'id') return -1;
40+
if (b === 'id') return 1;
41+
return a.localeCompare(b);
42+
})
2943
}, (e) => {
3044
ElMessage({
3145
showClose: true,
@@ -40,12 +54,19 @@ const executeQuery = async () => {
4054
<div>
4155
<el-form @submit.prevent="executeQuery">
4256
<el-row :gutter="10">
43-
<el-col :span="20">
57+
<el-col :span="2">
58+
<el-form-item>
59+
<el-select v-model="store" placeholder="Select store">
60+
<el-option v-for="item in stores" :key="item.name" :label="item.name" :value="item.name"></el-option>
61+
</el-select>
62+
</el-form-item>
63+
</el-col>
64+
<el-col :span="18">
4465
<el-form-item>
4566
<el-input v-model="sqlQuery" placeholder="Enter SQL query"></el-input>
4667
</el-form-item>
4768
</el-col>
48-
<el-col :span="4">
69+
<el-col :span="2">
4970
<el-form-item>
5071
<el-button type="primary" @click="executeQuery">Execute</el-button>
5172
</el-form-item>

console/atest-ui/src/views/net.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,11 +773,11 @@ var SBOM = (callback: (d: any) => void) => {
773773
.then(callback)
774774
}
775775

776-
var DataQuery = (query: string, callback: (d: any) => void, errHandler: (d: any) => void) => {
776+
var DataQuery = (store: string, query: string, callback: (d: any) => void, errHandler: (d: any) => void) => {
777777
const requestOptions = {
778778
method: 'POST',
779779
headers: {
780-
'X-Store-Name': 'mysql' //Cache.GetCurrentStore().name
780+
'X-Store-Name': store
781781
},
782782
body: JSON.stringify({
783783
sql: query

0 commit comments

Comments
 (0)