Skip to content

Commit 79b161e

Browse files
Merge branch 'LinuxSuRen:master' into master
2 parents a2a631e + dc4262d commit 79b161e

File tree

7 files changed

+215
-72
lines changed

7 files changed

+215
-72
lines changed

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

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import { ref, watch } from 'vue'
33
import { API } from './net'
44
import type { QueryObject } from './net'
55
import type { Store } from './store'
6+
import { Driver, GetDriverName, ExtensionKind } from './store'
67
import type { Pair } from './types'
78
import { GetDataManagerPreference, SetDataManagerPreference } from './cache'
89
import { ElMessage } from 'element-plus'
910
import { Codemirror } from 'vue-codemirror'
10-
import { sql, StandardSQL } from "@codemirror/lang-sql"
11+
import { sql, StandardSQL, MySQL, PostgreSQL, Cassandra } from "@codemirror/lang-sql"
12+
import type { SQLConfig } from "@codemirror/lang-sql"
1113
import HistoryInput from '../components/HistoryInput.vue'
1214
import type { Ref } from 'vue'
1315
import { Refresh, Document } from '@element-plus/icons-vue'
@@ -47,14 +49,27 @@ const storeChangedEvent = (s: string) => {
4749
stores.value.forEach((e: Store) => {
4850
if (e.name === s) {
4951
kind.value = e.kind.name
52+
switch (GetDriverName(e)){
53+
case Driver.MySQL:
54+
sqlConfig.value.dialect = MySQL
55+
break;
56+
case Driver.Postgres:
57+
sqlConfig.value.dialect = PostgreSQL
58+
break;
59+
case Driver.Cassandra:
60+
sqlConfig.value.dialect = Cassandra
61+
break;
62+
default:
63+
sqlConfig.value.dialect = StandardSQL
64+
}
5065
return
5166
}
5267
})
5368
5469
switch (kind.value) {
55-
case 'atest-store-elasticsearch':
56-
case 'atest-store-etcd':
57-
case 'atest-store-redis':
70+
case ExtensionKind.ExtensionKindElasticsearch:
71+
case ExtensionKind.ExtensionKindEtcd:
72+
case ExtensionKind.ExtensionKindRedis:
5873
sqlQuery.value = '*'
5974
complexEditor.value = false
6075
break
@@ -89,7 +104,7 @@ const queryDataFromTable = (data: QueryData) => {
89104
}
90105
const describeTable = (data: QueryData) => {
91106
switch (kind.value) {
92-
case 'atest-store-cassandra':
107+
case ExtensionKind.ExtensionKindCassandra:
93108
sqlQuery.value = `@describeTable_${queryDataMeta.value.currentDatabase}:${data.label}`
94109
break
95110
default:
@@ -102,17 +117,17 @@ const queryTables = () => {
102117
}
103118
watch(kind, (k) => {
104119
switch (k) {
105-
case 'atest-store-orm':
106-
case 'atest-store-cassandra':
107-
case 'atest-store-iotdb':
120+
case ExtensionKind.ExtensionKindORM:
121+
case ExtensionKind.ExtensionKindCassandra:
122+
case ExtensionKind.ExtensionKindIotDB:
108123
queryTip.value = 'Enter SQL query'
109124
executeQuery()
110125
break;
111-
case 'atest-store-etcd':
112-
case 'atest-store-redis':
126+
case ExtensionKind.ExtensionKindEtcd:
127+
case ExtensionKind.ExtensionKindRedis:
113128
queryTip.value = 'Enter key'
114129
break;
115-
case 'atest-store-elasticsearch':
130+
case ExtensionKind.ExtensionKindElasticsearch:
116131
queryTip.value = 'field:value OR field:other'
117132
break;
118133
}
@@ -139,6 +154,7 @@ API.GetStores((data) => {
139154
loadingStores.value = false
140155
})
141156
157+
const showNativeSQL = ref(true)
142158
const ormDataHandler = (data: QueryData) => {
143159
const result = [] as any[]
144160
const cols = new Set<string>()
@@ -154,7 +170,7 @@ const ormDataHandler = (data: QueryData) => {
154170
155171
columns.value = [] as string[]
156172
data.meta.labels = data.meta.labels.filter((item) => {
157-
if (item.key === '_native_sql') {
173+
if (showNativeSQL.value && item.key === '_native_sql') {
158174
sqlQuery.value = item.value
159175
return false
160176
}
@@ -196,20 +212,20 @@ const keyValueDataHandler = (data: QueryData) => {
196212
})
197213
})
198214
}
199-
200215
const sqlConfig = ref({
201216
dialect: StandardSQL,
202217
defaultSchema: queryDataMeta.value.currentDatabase,
203218
upperCaseKeywords: true,
204219
schema: {}
205-
})
220+
} as SQLConfig)
206221
207222
const executeQuery = async () => {
223+
showNativeSQL.value = true
208224
if (sqlQuery.value === '') {
209225
switch (kind.value) {
210-
case 'atest-store-elasticsearch':
211-
case 'atest-store-etcd':
212-
case 'atest-store-redis':
226+
case ExtensionKind.ExtensionKindElasticsearch:
227+
case ExtensionKind.ExtensionKindEtcd:
228+
case ExtensionKind.ExtensionKindRedis:
213229
if (sqlQuery.value === '') {
214230
sqlQuery.value = '*'
215231
}
@@ -227,16 +243,16 @@ const executeWithQuery = async (sql: string) => {
227243
try {
228244
const data = await API.DataQueryAsync(query.value);
229245
switch (kind.value) {
230-
case 'atest-store-orm':
231-
case 'atest-store-cassandra':
232-
case 'atest-store-iotdb':
233-
case 'atest-store-opengemini':
234-
case 'atest-store-elasticsearch':
246+
case ExtensionKind.ExtensionKindORM:
247+
case ExtensionKind.ExtensionKindCassandra:
248+
case ExtensionKind.ExtensionKindIotDB:
249+
case ExtensionKind.ExtensionKindOpengeMini:
250+
case ExtensionKind.ExtensionKindElasticsearch:
235251
ormDataHandler(data)
236252
success = true
237253
break;
238-
case 'atest-store-etcd':
239-
case 'atest-store-redis':
254+
case ExtensionKind.ExtensionKindEtcd:
255+
case ExtensionKind.ExtensionKindRedis:
240256
keyValueDataHandler(data)
241257
break;
242258
default:
@@ -277,6 +293,13 @@ Magic.AdvancedKeys([{
277293
Keys: ['Ctrl+E', 'Ctrl+Enter'],
278294
Func: executeQuery,
279295
Description: 'Execute query'
296+
}, {
297+
Keys: ['Ctrl+Shift+O'],
298+
Func: () => {
299+
showNativeSQL.value = false
300+
executeWithQuery(sqlQuery.value)
301+
},
302+
Description: 'Execute query without showing native SQL'
280303
}])
281304
</script>
282305

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

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { ref, watch, reactive } from 'vue'
2+
import { ref, watch } from 'vue'
33
import { ElMessage } from 'element-plus'
44
import { Edit, Delete, Search, CopyDocument, Help } from '@element-plus/icons-vue'
55
import JsonViewer from 'vue-json-viewer'
@@ -20,9 +20,7 @@ import jsonlint from 'jsonlint-mod'
2020
2121
import CodeMirror from 'codemirror'
2222
import { json, jsonLanguage } from "@codemirror/lang-json"
23-
import { LanguageSupport } from "@codemirror/language"
24-
import { CompletionContext } from "@codemirror/autocomplete"
25-
import type { Completion } from "@codemirror/autocomplete"
23+
import { NewLanguageComplete } from './languageComplete'
2624
import 'codemirror/lib/codemirror.css'
2725
import 'codemirror/addon/merge/merge.js'
2826
import 'codemirror/addon/merge/merge.css'
@@ -34,36 +32,7 @@ window.DIFF_DELETE = -1;
3432
window.DIFF_INSERT = 1;
3533
window.DIFF_EQUAL = 0;
3634
37-
const templateFuncs = ref([] as Completion[])
38-
function myCompletions(context: CompletionContext) {
39-
if (templateFuncs.value.length == 0) {
40-
API.FunctionsQuery("", "template", (e) => {
41-
if (e.data) {
42-
e.data.forEach((item: any) => {
43-
templateFuncs.value.push({
44-
label: item.key,
45-
type: "text",
46-
} as Completion)
47-
})
48-
}
49-
})
50-
}
51-
52-
let word = context.matchBefore(/\w*/) || {
53-
from: "",
54-
to: ""
55-
}
56-
if (word.from == word.to && !context.explicit)
57-
return null
58-
return {
59-
from: word.from,
60-
options: templateFuncs.value
61-
}
62-
}
63-
const jsonComplete = new LanguageSupport(jsonLanguage, jsonLanguage.data.of(
64-
{autocomplete: myCompletions}
65-
))
66-
35+
const jsonComplete = NewLanguageComplete(jsonLanguage)
6736
const { t } = useI18n()
6837
6938
const props = defineProps({
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Language, LanguageSupport } from "@codemirror/language"
2+
import { CompletionContext } from "@codemirror/autocomplete"
3+
import type { Completion } from "@codemirror/autocomplete"
4+
import { API } from './net'
5+
import { ref } from 'vue'
6+
7+
const templateFuncs = ref([] as Completion[])
8+
function tplFuncCompletions(context: CompletionContext) {
9+
if (templateFuncs.value.length == 0) {
10+
API.FunctionsQuery("", "template", (e) => {
11+
if (e.data) {
12+
e.data.forEach((item: any) => {
13+
templateFuncs.value.push({
14+
label: item.key,
15+
type: "text",
16+
} as Completion)
17+
})
18+
}
19+
})
20+
}
21+
22+
let word = context.matchBefore(/\w*/) || {
23+
from: "",
24+
to: ""
25+
}
26+
if (word.from == word.to && !context.explicit)
27+
return null
28+
return {
29+
from: word.from,
30+
options: templateFuncs.value
31+
}
32+
}
33+
34+
export const NewLanguageComplete = (lang: Language) => {
35+
return new LanguageSupport(lang, lang.data.of(
36+
{autocomplete: tplFuncCompletions}
37+
))
38+
}

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

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,57 @@ export interface Store {
2323
name: string;
2424
description: string;
2525
};
26+
properties: Pair[];
2627
params: Pair[];
2728
}
2829

30+
const MySQL = "mysql";
31+
const Postgres = "postgres";
32+
const SQLite = "sqlite";
33+
const TDengine = "tdengine";
34+
const Cassandra = "cassandra";
35+
36+
export const GetDriverName = (store: Store): string => {
37+
switch (store.kind.name) {
38+
case 'atest-store-orm':
39+
return store.properties.find((p: Pair) => p.key === 'driver')?.value || MySQL;
40+
case 'atest-store-cassandra':
41+
return Cassandra;
42+
}
43+
return ""
44+
}
45+
46+
export const Driver = {
47+
MySQL, Postgres, SQLite, TDengine, Cassandra
48+
}
49+
50+
const ExtensionKindGit = "atest-store-git"
51+
const ExtensionKindS3 = "atest-store-s3"
52+
const ExtensionKindORM = "atest-store-orm"
53+
const ExtensionKindIotDB = "atest-store-iotdb"
54+
const ExtensionKindCassandra = "atest-store-cassandra"
55+
const ExtensionKindEtcd = "atest-store-etcd"
56+
const ExtensionKindRedis = "atest-store-redis"
57+
const ExtensionKindMongoDB = "atest-store-mongodb"
58+
const ExtensionKindElasticsearch = "atest-store-elasticsearch"
59+
const ExtensionKindOpengeMini = "atest-store-opengemini"
60+
61+
export const ExtensionKind = {
62+
ExtensionKindGit,
63+
ExtensionKindS3,
64+
ExtensionKindORM,
65+
ExtensionKindIotDB,
66+
ExtensionKindCassandra,
67+
ExtensionKindEtcd,
68+
ExtensionKindRedis,
69+
ExtensionKindMongoDB,
70+
ExtensionKindElasticsearch,
71+
ExtensionKindOpengeMini
72+
}
73+
2974
const storeExtensions = [
3075
{
31-
name: 'atest-store-git',
76+
name: ExtensionKindGit,
3277
params: [{
3378
key: 'insecure'
3479
}, {
@@ -47,7 +92,7 @@ const storeExtensions = [
4792
link: 'https://github.com/LinuxSuRen/atest-ext-store-git'
4893
},
4994
{
50-
name: 'atest-store-s3',
95+
name: ExtensionKindS3,
5196
params: [{
5297
key: 'accesskeyid'
5398
}, {
@@ -66,11 +111,11 @@ const storeExtensions = [
66111
link: 'https://github.com/LinuxSuRen/atest-ext-store-s3'
67112
},
68113
{
69-
name: 'atest-store-orm',
114+
name: ExtensionKindORM,
70115
params: [{
71116
key: 'driver',
72117
defaultValue: 'mysql',
73-
enum: ['mysql', 'postgres', 'sqlite', 'tdengine'],
118+
enum: [MySQL, Postgres, SQLite, TDengine],
74119
description: 'Supported: mysql, postgres, sqlite, tdengine'
75120
}, {
76121
key: 'database',
@@ -84,30 +129,30 @@ const storeExtensions = [
84129
link: 'https://github.com/LinuxSuRen/atest-ext-store-orm'
85130
},
86131
{
87-
name: 'atest-store-iotdb',
132+
name: ExtensionKindIotDB,
88133
params: [],
89134
link: 'https://github.com/LinuxSuRen/atest-ext-store-iotdb'
90135
},
91136
{
92-
name: 'atest-store-cassandra',
137+
name: ExtensionKindCassandra,
93138
params: [{
94139
key: 'keyspace',
95140
defaultValue: ''
96141
}],
97142
link: 'https://github.com/LinuxSuRen/atest-ext-store-cassandra'
98143
},
99144
{
100-
name: 'atest-store-etcd',
145+
name: ExtensionKindEtcd,
101146
params: [],
102147
link: 'https://github.com/LinuxSuRen/atest-ext-store-etcd'
103148
},
104149
{
105-
name: 'atest-store-redis',
150+
name: ExtensionKindRedis,
106151
params: [],
107152
link: 'https://github.com/LinuxSuRen/atest-ext-store-redis'
108153
},
109154
{
110-
name: 'atest-store-mongodb',
155+
name: ExtensionKindMongoDB,
111156
params: [{
112157
key: 'collection'
113158
}, {
@@ -117,12 +162,12 @@ const storeExtensions = [
117162
link: 'https://github.com/LinuxSuRen/atest-ext-store-mongodb'
118163
},
119164
{
120-
name: 'atest-store-elasticsearch',
165+
name: ExtensionKindElasticsearch,
121166
params: [],
122167
link: 'https://github.com/LinuxSuRen/atest-ext-store-elasticsearch'
123168
},
124169
{
125-
name: 'atest-store-opengemini',
170+
name: ExtensionKindOpengeMini,
126171
params: [],
127172
link: 'https://github.com/LinuxSuRen/atest-ext-store-opengemini'
128173
}

0 commit comments

Comments
 (0)