Skip to content

Commit c0c227e

Browse files
authored
chore: support changing sql dialect (#725)
Co-authored-by: rick <[email protected]>
1 parent 1ba3d25 commit c0c227e

File tree

3 files changed

+92
-33
lines changed

3 files changed

+92
-33
lines changed

console/atest-ui/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ 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"
1112
import HistoryInput from '../components/HistoryInput.vue'
1213
import type { Ref } from 'vue'
1314
import { Refresh, Document } from '@element-plus/icons-vue'
@@ -47,14 +48,27 @@ const storeChangedEvent = (s: string) => {
4748
stores.value.forEach((e: Store) => {
4849
if (e.name === s) {
4950
kind.value = e.kind.name
51+
switch (GetDriverName(e)){
52+
case Driver.MySQL:
53+
sqlConfig.value.dialect = MySQL
54+
break;
55+
case Driver.Postgres:
56+
sqlConfig.value.dialect = PostgreSQL
57+
break;
58+
case Driver.Cassandra:
59+
sqlConfig.value.dialect = Cassandra
60+
break;
61+
default:
62+
sqlConfig.value.dialect = StandardSQL
63+
}
5064
return
5165
}
5266
})
5367
5468
switch (kind.value) {
55-
case 'atest-store-elasticsearch':
56-
case 'atest-store-etcd':
57-
case 'atest-store-redis':
69+
case ExtensionKind.ExtensionKindElasticsearch:
70+
case ExtensionKind.ExtensionKindEtcd:
71+
case ExtensionKind.ExtensionKindRedis:
5872
sqlQuery.value = '*'
5973
complexEditor.value = false
6074
break
@@ -89,7 +103,7 @@ const queryDataFromTable = (data: QueryData) => {
89103
}
90104
const describeTable = (data: QueryData) => {
91105
switch (kind.value) {
92-
case 'atest-store-cassandra':
106+
case ExtensionKind.ExtensionKindCassandra:
93107
sqlQuery.value = `@describeTable_${queryDataMeta.value.currentDatabase}:${data.label}`
94108
break
95109
default:
@@ -102,17 +116,17 @@ const queryTables = () => {
102116
}
103117
watch(kind, (k) => {
104118
switch (k) {
105-
case 'atest-store-orm':
106-
case 'atest-store-cassandra':
107-
case 'atest-store-iotdb':
119+
case ExtensionKind.ExtensionKindORM:
120+
case ExtensionKind.ExtensionKindCassandra:
121+
case ExtensionKind.ExtensionKindIotDB:
108122
queryTip.value = 'Enter SQL query'
109123
executeQuery()
110124
break;
111-
case 'atest-store-etcd':
112-
case 'atest-store-redis':
125+
case ExtensionKind.ExtensionKindEtcd:
126+
case ExtensionKind.ExtensionKindRedis:
113127
queryTip.value = 'Enter key'
114128
break;
115-
case 'atest-store-elasticsearch':
129+
case ExtensionKind.ExtensionKindElasticsearch:
116130
queryTip.value = 'field:value OR field:other'
117131
break;
118132
}
@@ -207,9 +221,9 @@ const sqlConfig = ref({
207221
const executeQuery = async () => {
208222
if (sqlQuery.value === '') {
209223
switch (kind.value) {
210-
case 'atest-store-elasticsearch':
211-
case 'atest-store-etcd':
212-
case 'atest-store-redis':
224+
case ExtensionKind.ExtensionKindElasticsearch:
225+
case ExtensionKind.ExtensionKindEtcd:
226+
case ExtensionKind.ExtensionKindRedis:
213227
if (sqlQuery.value === '') {
214228
sqlQuery.value = '*'
215229
}
@@ -227,16 +241,16 @@ const executeWithQuery = async (sql: string) => {
227241
try {
228242
const data = await API.DataQueryAsync(query.value);
229243
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':
244+
case ExtensionKind.ExtensionKindORM:
245+
case ExtensionKind.ExtensionKindCassandra:
246+
case ExtensionKind.ExtensionKindIotDB:
247+
case ExtensionKind.ExtensionKindOpengeMini:
248+
case ExtensionKind.ExtensionKindElasticsearch:
235249
ormDataHandler(data)
236250
success = true
237251
break;
238-
case 'atest-store-etcd':
239-
case 'atest-store-redis':
252+
case ExtensionKind.ExtensionKindEtcd:
253+
case ExtensionKind.ExtensionKindRedis:
240254
keyValueDataHandler(data)
241255
break;
242256
default:

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)