@@ -64,6 +64,8 @@ func (s *dbserver) Query(ctx context.Context, query *server.DataQuery) (result *
64
64
return
65
65
}
66
66
67
+ result .Meta .Labels = dbQuery .GetLabels (ctx , query .Sql )
68
+
67
69
var dataResult * server.DataQueryResult
68
70
now := time .Now ()
69
71
if dataResult , err = sqlQuery (ctx , query .Sql , db ); err == nil {
@@ -166,6 +168,7 @@ type DataQuery interface {
166
168
GetDatabases (context.Context ) (databases []string , err error )
167
169
GetTables (ctx context.Context , currentDatabase string ) (tables []string , err error )
168
170
GetCurrentDatabase () (string , error )
171
+ GetLabels (context.Context , string ) map [string ]string
169
172
GetClient () * gorm.DB
170
173
}
171
174
@@ -236,6 +239,7 @@ func (q *commonDataQuery) GetTables(ctx context.Context, currentDatabase string)
236
239
}
237
240
return
238
241
}
242
+
239
243
func (q * commonDataQuery ) GetCurrentDatabase () (current string , err error ) {
240
244
var row * sql.Row
241
245
if row = q .db .Raw (q .currentDatabase ).Row (); row != nil {
@@ -244,6 +248,21 @@ func (q *commonDataQuery) GetCurrentDatabase() (current string, err error) {
244
248
return
245
249
}
246
250
251
+ func (q * commonDataQuery ) GetLabels (ctx context.Context , sql string ) (metadata map [string ]string ) {
252
+ if databaseResult , err := sqlQuery (ctx , fmt .Sprintf ("explain %s" , sql ), q .db ); err == nil {
253
+ if len (databaseResult .Items ) != 1 {
254
+ metadata = make (map [string ]string )
255
+ for _ , data := range databaseResult .Items [0 ].Data {
256
+ switch data .Key {
257
+ case "type" :
258
+ metadata ["sql_type" ] = data .Value
259
+ }
260
+ }
261
+ }
262
+ }
263
+ return
264
+ }
265
+
247
266
func (q * commonDataQuery ) GetClient () * gorm.DB {
248
267
return q .db
249
268
}
0 commit comments