fdb2 1.0.39 → 1.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +6 -5
  2. package/dist/public/.vite/manifest.json +109 -1
  3. package/dist/public/database-monitor.css +445 -0
  4. package/dist/public/database-monitor.js +605 -0
  5. package/dist/public/database.css +740 -0
  6. package/dist/public/database.js +555 -0
  7. package/dist/public/database2.js +344 -0
  8. package/dist/public/echarts.js +79307 -0
  9. package/dist/public/explorer.css +1109 -436
  10. package/dist/public/explorer.js +4049 -34891
  11. package/dist/public/export.js +54831 -0
  12. package/dist/public/helpers.js +27 -0
  13. package/dist/public/index.js +545 -51
  14. package/dist/public/layout.css +98 -65
  15. package/dist/public/layout.js +59 -22
  16. package/dist/public/query-history.css +651 -0
  17. package/dist/public/query-history.js +526 -0
  18. package/dist/public/sql-query-editor.css +503 -0
  19. package/dist/public/sql-query-editor.js +638 -0
  20. package/dist/public/theme.js +82 -0
  21. package/dist/scripts/verify-db-support.cjs +239 -0
  22. package/dist/server/__tests__/import-normalize.test.ts +79 -0
  23. package/dist/server/__tests__/remote-proxy.test.ts +62 -0
  24. package/dist/server/core/dialect.d.ts +9 -0
  25. package/dist/server/core/dialect.d.ts.map +1 -1
  26. package/dist/server/core/dialect.js +24 -9
  27. package/dist/server/core/dialect.js.map +1 -1
  28. package/dist/server/core/dialect.ts +29 -9
  29. package/dist/server/core/schema/__tests__/ddl-emitter.test.ts +159 -3
  30. package/dist/server/core/schema/canonical.d.ts.map +1 -1
  31. package/dist/server/core/schema/canonical.js +4 -1
  32. package/dist/server/core/schema/canonical.js.map +1 -1
  33. package/dist/server/core/schema/canonical.ts +4 -1
  34. package/dist/server/core/schema/ddl-emitter.d.ts +3 -0
  35. package/dist/server/core/schema/ddl-emitter.d.ts.map +1 -1
  36. package/dist/server/core/schema/ddl-emitter.js +158 -24
  37. package/dist/server/core/schema/ddl-emitter.js.map +1 -1
  38. package/dist/server/core/schema/ddl-emitter.ts +171 -22
  39. package/dist/server/index.d.ts +20 -0
  40. package/dist/server/index.d.ts.map +1 -1
  41. package/dist/server/index.js +375 -25
  42. package/dist/server/index.js.map +1 -1
  43. package/dist/server/index.ts +392 -27
  44. package/dist/server/model/ddl-spec.d.ts +9 -0
  45. package/dist/server/model/ddl-spec.d.ts.map +1 -1
  46. package/dist/server/model/ddl-spec.ts +9 -0
  47. package/dist/server/service/connection.service.d.ts +8 -0
  48. package/dist/server/service/connection.service.d.ts.map +1 -1
  49. package/dist/server/service/connection.service.js +75 -17
  50. package/dist/server/service/connection.service.js.map +1 -1
  51. package/dist/server/service/connection.service.ts +74 -17
  52. package/dist/server/service/database/base.service.d.ts +45 -0
  53. package/dist/server/service/database/base.service.d.ts.map +1 -1
  54. package/dist/server/service/database/base.service.js +120 -7
  55. package/dist/server/service/database/base.service.js.map +1 -1
  56. package/dist/server/service/database/base.service.ts +143 -8
  57. package/dist/server/service/database/cockroachdb.service.d.ts +9 -0
  58. package/dist/server/service/database/cockroachdb.service.d.ts.map +1 -1
  59. package/dist/server/service/database/cockroachdb.service.js +68 -57
  60. package/dist/server/service/database/cockroachdb.service.js.map +1 -1
  61. package/dist/server/service/database/cockroachdb.service.ts +67 -58
  62. package/dist/server/service/database/database.service.d.ts +25 -227
  63. package/dist/server/service/database/database.service.d.ts.map +1 -1
  64. package/dist/server/service/database/database.service.js +323 -78
  65. package/dist/server/service/database/database.service.js.map +1 -1
  66. package/dist/server/service/database/database.service.ts +334 -87
  67. package/dist/server/service/database/mongodb.service.d.ts +58 -3
  68. package/dist/server/service/database/mongodb.service.d.ts.map +1 -1
  69. package/dist/server/service/database/mongodb.service.js +264 -54
  70. package/dist/server/service/database/mongodb.service.js.map +1 -1
  71. package/dist/server/service/database/mongodb.service.ts +288 -60
  72. package/dist/server/service/database/mssql.service.d.ts +8 -0
  73. package/dist/server/service/database/mssql.service.d.ts.map +1 -1
  74. package/dist/server/service/database/mssql.service.js +45 -40
  75. package/dist/server/service/database/mssql.service.js.map +1 -1
  76. package/dist/server/service/database/mssql.service.ts +49 -44
  77. package/dist/server/service/database/oracle.service.d.ts +29 -1
  78. package/dist/server/service/database/oracle.service.d.ts.map +1 -1
  79. package/dist/server/service/database/oracle.service.js +166 -137
  80. package/dist/server/service/database/oracle.service.js.map +1 -1
  81. package/dist/server/service/database/oracle.service.ts +166 -146
  82. package/dist/server/service/database/sap.service.d.ts +8 -0
  83. package/dist/server/service/database/sap.service.d.ts.map +1 -1
  84. package/dist/server/service/database/sap.service.js +28 -0
  85. package/dist/server/service/database/sap.service.js.map +1 -1
  86. package/dist/server/service/database/sap.service.ts +29 -0
  87. package/dist/server/service/database/sqlite.service.d.ts.map +1 -1
  88. package/dist/server/service/database/sqlite.service.js +6 -3
  89. package/dist/server/service/database/sqlite.service.js.map +1 -1
  90. package/dist/server/service/database/sqlite.service.ts +6 -3
  91. package/package.json +8 -8
  92. package/public/fdb2.png +0 -0
  93. package/scripts/verify-db-support.cjs +239 -0
@@ -0,0 +1,638 @@
1
+ import { n as __esmMin } from "./rolldown-runtime.js";
2
+ import { A as defineComponent, B as renderList, F as nextTick, G as watch, L as onMounted, O as createTextVNode, S as createBaseVNode, T as createElementBlock, _ as vModelText, a as init_vue_router, b as Fragment, d as init_vue_runtime_esm_bundler, g as vModelSelect, l as init_vue_i18n, lt as toDisplayString, nt as ref, o as useRoute, q as withDirectives, st as normalizeClass, u as useI18n, w as createCommentVNode, x as computed, z as openBlock } from "./vue.js";
3
+ import { A as isVSCodeEnvironment, O as getVSCodeBridge, _ as init__plugin_vue_export_helper, g as _plugin_vue_export_helper_default, k as init_bridge } from "./index.js";
4
+ import { n as DatabaseService, r as init_database, t as ConnectionService } from "./database.js";
5
+ import { o as init_export, t as exportDataToCSV } from "./export.js";
6
+ //#region src/platform/database/components/sql-query-editor.vue?vue&type=script&setup=true&lang.ts
7
+ var _hoisted_1, _hoisted_2, _hoisted_3, _hoisted_4, _hoisted_5, _hoisted_6, _hoisted_7, _hoisted_8, _hoisted_9, _hoisted_10, _hoisted_11, _hoisted_12, _hoisted_13, _hoisted_14, _hoisted_15, _hoisted_16, _hoisted_17, _hoisted_18, _hoisted_19, _hoisted_20, _hoisted_21, _hoisted_22, _hoisted_23, _hoisted_24, _hoisted_25, _hoisted_26, _hoisted_27, _hoisted_28, _hoisted_29, _hoisted_30, _hoisted_31, _hoisted_32, _hoisted_33, _hoisted_34, _hoisted_35, _hoisted_36, _hoisted_37, _hoisted_38, _hoisted_39, _hoisted_40, _hoisted_41, _hoisted_42, _hoisted_43, _hoisted_44, _hoisted_45, SAVED_QUERIES_KEY, QUERY_HISTORY_KEY, sql_query_editor_vue_vue_type_script_setup_true_lang_default;
8
+ var init_sql_query_editor_vue_vue_type_script_setup_true_lang = __esmMin((() => {
9
+ init_vue_runtime_esm_bundler();
10
+ init_vue_router();
11
+ init_vue_i18n();
12
+ init_database();
13
+ init_bridge();
14
+ init_export();
15
+ _hoisted_1 = { class: "sql-query-editor" };
16
+ _hoisted_2 = { class: "query-header" };
17
+ _hoisted_3 = { class: "query-controls" };
18
+ _hoisted_4 = ["value"];
19
+ _hoisted_5 = { value: "" };
20
+ _hoisted_6 = ["value"];
21
+ _hoisted_7 = ["disabled"];
22
+ _hoisted_8 = ["disabled"];
23
+ _hoisted_9 = ["disabled"];
24
+ _hoisted_10 = {
25
+ key: 0,
26
+ class: "saved-queries"
27
+ };
28
+ _hoisted_11 = { class: "saved-queries-label" };
29
+ _hoisted_12 = ["title", "onClick"];
30
+ _hoisted_13 = { class: "query-editor-wrapper" };
31
+ _hoisted_14 = { class: "editor-toolbar" };
32
+ _hoisted_15 = { class: "toolbar-left" };
33
+ _hoisted_16 = ["onClick", "title"];
34
+ _hoisted_17 = { class: "toolbar-right" };
35
+ _hoisted_18 = { class: "line-info" };
36
+ _hoisted_19 = { class: "sql-mode" };
37
+ _hoisted_20 = { class: "editor-container" };
38
+ _hoisted_21 = {
39
+ key: 1,
40
+ class: "query-results"
41
+ };
42
+ _hoisted_22 = { class: "results-header" };
43
+ _hoisted_23 = { class: "results-info" };
44
+ _hoisted_24 = {
45
+ key: 0,
46
+ class: "results-count"
47
+ };
48
+ _hoisted_25 = { class: "results-actions" };
49
+ _hoisted_26 = { class: "results-content" };
50
+ _hoisted_27 = {
51
+ key: 0,
52
+ class: "error-message"
53
+ };
54
+ _hoisted_28 = {
55
+ key: 1,
56
+ class: "results-table-wrapper"
57
+ };
58
+ _hoisted_29 = { class: "results-table" };
59
+ _hoisted_30 = ["onClick"];
60
+ _hoisted_31 = {
61
+ key: 0,
62
+ class: "bi bi-arrow-down-up"
63
+ };
64
+ _hoisted_32 = ["title"];
65
+ _hoisted_33 = { key: 0 };
66
+ _hoisted_34 = ["colspan"];
67
+ _hoisted_35 = {
68
+ key: 0,
69
+ class: "pagination"
70
+ };
71
+ _hoisted_36 = ["disabled"];
72
+ _hoisted_37 = { class: "page-info" };
73
+ _hoisted_38 = ["disabled"];
74
+ _hoisted_39 = {
75
+ key: 2,
76
+ class: "modal-overlay"
77
+ };
78
+ _hoisted_40 = { class: "modal-content" };
79
+ _hoisted_41 = { class: "modal-body" };
80
+ _hoisted_42 = { class: "form-group" };
81
+ _hoisted_43 = { class: "form-group" };
82
+ _hoisted_44 = { class: "modal-footer" };
83
+ _hoisted_45 = ["disabled"];
84
+ SAVED_QUERIES_KEY = "fdb2.savedQueries";
85
+ QUERY_HISTORY_KEY = "fdb2.queryHistory";
86
+ sql_query_editor_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
87
+ __name: "sql-query-editor",
88
+ setup(__props) {
89
+ const connectionService = new ConnectionService();
90
+ const databaseService = new DatabaseService();
91
+ const route = useRoute();
92
+ const { t } = useI18n();
93
+ const querySql = ref("");
94
+ const selectedConnection = ref("");
95
+ const selectedDatabase = ref("");
96
+ const connections = ref([]);
97
+ const databases = ref([]);
98
+ const queryResults = ref([]);
99
+ const resultColumns = ref([]);
100
+ const savedQueries = ref([]);
101
+ const isExecuting = ref(false);
102
+ const queryError = ref("");
103
+ const currentLine = ref(1);
104
+ const currentColumn = ref(1);
105
+ const showSaveDialog = ref(false);
106
+ const queryName = ref("");
107
+ const queryDescription = ref("");
108
+ const currentPage = ref(1);
109
+ const pageSize = ref(50);
110
+ const sortColumn = ref("");
111
+ const sortDirection = ref("asc");
112
+ const sqlSnippets = ref([
113
+ {
114
+ name: "SELECT",
115
+ icon: "bi-cursor-text",
116
+ description: "SELECT语句模板",
117
+ template: "SELECT * FROM table_name WHERE condition;"
118
+ },
119
+ {
120
+ name: "INSERT",
121
+ icon: "bi-plus-square",
122
+ description: "INSERT语句模板",
123
+ template: "INSERT INTO table_name (column1, column2) VALUES (value1, value2);"
124
+ },
125
+ {
126
+ name: "UPDATE",
127
+ icon: "bi-pencil-square",
128
+ description: "UPDATE语句模板",
129
+ template: "UPDATE table_name SET column1 = value1 WHERE condition;"
130
+ },
131
+ {
132
+ name: "DELETE",
133
+ icon: "bi-trash",
134
+ description: "DELETE语句模板",
135
+ template: "DELETE FROM table_name WHERE condition;"
136
+ },
137
+ {
138
+ name: "JOIN",
139
+ icon: "bi-link-45deg",
140
+ description: "JOIN语句模板",
141
+ template: "SELECT a.*, b.* FROM table_a a JOIN table_b b ON a.id = b.id;"
142
+ },
143
+ {
144
+ name: "FUNCTION",
145
+ icon: "bi-gear",
146
+ description: "函数模板",
147
+ template: "SELECT COUNT(*), AVG(column), MAX(column), MIN(column) FROM table_name;"
148
+ }
149
+ ]);
150
+ const lineCount = computed(() => {
151
+ return querySql.value.split("\n").length;
152
+ });
153
+ const columns = computed(() => {
154
+ if (resultColumns.value.length > 0) return resultColumns.value;
155
+ if (queryResults.value.length === 0) return [];
156
+ return Object.keys(queryResults.value[0]);
157
+ });
158
+ const sortedResults = computed(() => {
159
+ if (!sortColumn.value) return queryResults.value;
160
+ return [...queryResults.value].sort((a, b) => {
161
+ const aVal = a[sortColumn.value];
162
+ const bVal = b[sortColumn.value];
163
+ if (aVal === null || aVal === void 0) return 1;
164
+ if (bVal === null || bVal === void 0) return -1;
165
+ let comparison = 0;
166
+ if (typeof aVal === "number" && typeof bVal === "number") comparison = aVal - bVal;
167
+ else comparison = String(aVal).localeCompare(String(bVal));
168
+ return sortDirection.value === "asc" ? comparison : -comparison;
169
+ });
170
+ });
171
+ const totalPages = computed(() => {
172
+ return Math.ceil(sortedResults.value.length / pageSize.value);
173
+ });
174
+ const paginatedResults = computed(() => {
175
+ const start = (currentPage.value - 1) * pageSize.value;
176
+ const end = start + pageSize.value;
177
+ return sortedResults.value.slice(start, end);
178
+ });
179
+ const sqlEditor = ref();
180
+ const lineNumbers = ref();
181
+ function readPersisted(key, stateKey) {
182
+ if (isVSCodeEnvironment()) {
183
+ const state = getVSCodeBridge().getState() || {};
184
+ return Array.isArray(state[stateKey]) ? state[stateKey] : [];
185
+ }
186
+ try {
187
+ const parsed = JSON.parse(localStorage.getItem(key) || "[]");
188
+ return Array.isArray(parsed) ? parsed : [];
189
+ } catch (e) {
190
+ console.warn("读取本地数据失败:", e);
191
+ return [];
192
+ }
193
+ }
194
+ function writePersisted(key, stateKey, value) {
195
+ if (isVSCodeEnvironment()) {
196
+ const bridge = getVSCodeBridge();
197
+ bridge.setState({
198
+ ...bridge.getState() || {},
199
+ [stateKey]: value
200
+ });
201
+ return;
202
+ }
203
+ try {
204
+ localStorage.setItem(key, JSON.stringify(value));
205
+ } catch (e) {
206
+ console.warn("保存本地数据失败:", e);
207
+ }
208
+ }
209
+ function getSqlType(sql) {
210
+ const match = sql.trim().match(/^[A-Za-z]+/);
211
+ return match ? match[0].toUpperCase() : "SQL";
212
+ }
213
+ function appendQueryHistory(record) {
214
+ const history = readPersisted(QUERY_HISTORY_KEY, "queryHistory");
215
+ history.unshift(record);
216
+ writePersisted(QUERY_HISTORY_KEY, "queryHistory", history.slice(0, 100));
217
+ }
218
+ function loadSavedQueries() {
219
+ savedQueries.value = readPersisted(SAVED_QUERIES_KEY, "savedQueries").filter((item) => item && typeof item.sql === "string").map((item) => ({
220
+ id: String(item.id || `${Date.now()}-${Math.random()}`),
221
+ name: String(item.name || t("sqlQueryEditor.unnamedQuery")),
222
+ description: String(item.description || ""),
223
+ sql: item.sql,
224
+ connectionId: String(item.connectionId || ""),
225
+ database: String(item.database || ""),
226
+ createdAt: String(item.createdAt || "")
227
+ }));
228
+ }
229
+ async function loadConnections() {
230
+ try {
231
+ const response = await connectionService.getAllConnections();
232
+ connections.value = response?.data || [];
233
+ } catch (error) {
234
+ console.error("加载连接列表失败:", error);
235
+ }
236
+ }
237
+ async function loadDatabases() {
238
+ databases.value = [];
239
+ selectedDatabase.value = "";
240
+ if (!selectedConnection.value) return;
241
+ try {
242
+ const response = await databaseService.getDatabases(String(selectedConnection.value));
243
+ const data = response?.data ?? response;
244
+ const list = data?.databases ?? (Array.isArray(data) ? data : []);
245
+ databases.value = Array.isArray(list) ? list.map((db) => typeof db === "string" ? db : db?.name).filter(Boolean) : [];
246
+ } catch (error) {
247
+ console.error("加载数据库列表失败:", error);
248
+ }
249
+ }
250
+ function handleInput() {
251
+ updateCursorInfo();
252
+ }
253
+ function handleKeydown(event) {
254
+ if (event.key === "Tab") {
255
+ event.preventDefault();
256
+ const textarea = sqlEditor.value;
257
+ if (!textarea) return;
258
+ const start = textarea.selectionStart;
259
+ const end = textarea.selectionEnd;
260
+ const text = querySql.value;
261
+ const newText = text.substring(0, start) + " " + text.substring(end);
262
+ querySql.value = newText;
263
+ nextTick(() => {
264
+ textarea.selectionStart = textarea.selectionEnd = start + 2;
265
+ updateCursorInfo();
266
+ });
267
+ }
268
+ if (event.ctrlKey && event.key === "Enter") executeQuery();
269
+ }
270
+ function updateCursorInfo() {
271
+ const textarea = sqlEditor.value;
272
+ if (!textarea) return;
273
+ const text = textarea.value;
274
+ const position = textarea.selectionStart;
275
+ const lines = text.substring(0, position).split("\n");
276
+ currentLine.value = lines.length;
277
+ currentColumn.value = (lines[lines.length - 1] || "").length + 1;
278
+ }
279
+ function syncScroll() {
280
+ if (sqlEditor.value && lineNumbers.value) lineNumbers.value.scrollTop = sqlEditor.value.scrollTop;
281
+ }
282
+ function insertSnippet(snippet) {
283
+ const textarea = sqlEditor.value;
284
+ if (!textarea) return;
285
+ const start = textarea.selectionStart;
286
+ const end = textarea.selectionEnd;
287
+ const text = querySql.value;
288
+ const newText = text.substring(0, start) + snippet.template + text.substring(end);
289
+ querySql.value = newText;
290
+ nextTick(() => {
291
+ textarea.focus();
292
+ updateCursorInfo();
293
+ });
294
+ }
295
+ async function executeQuery() {
296
+ if (!querySql.value.trim() || !selectedConnection.value || isExecuting.value) return;
297
+ const sql = querySql.value.trim();
298
+ const connectionId = String(selectedConnection.value);
299
+ const database = String(selectedDatabase.value || "") || void 0;
300
+ const connectionName = connections.value.find((c) => String(c.id) === connectionId)?.name || "";
301
+ const start = Date.now();
302
+ queryError.value = "";
303
+ queryResults.value = [];
304
+ resultColumns.value = [];
305
+ currentPage.value = 1;
306
+ isExecuting.value = true;
307
+ try {
308
+ const response = await databaseService.executeQuery(connectionId, sql, database);
309
+ const envelope = response?.data ?? response;
310
+ const result = envelope?.columns ? envelope : envelope?.data ?? envelope;
311
+ const rawColumns = Array.isArray(result?.columns) ? result.columns : [];
312
+ const rows = (Array.isArray(result?.rows) ? result.rows : Array.isArray(result) ? result : []).map((row) => {
313
+ if (!Array.isArray(row)) return row;
314
+ return rawColumns.reduce((obj, column, index) => {
315
+ obj[String(column)] = row[index];
316
+ return obj;
317
+ }, {});
318
+ });
319
+ resultColumns.value = rawColumns.map(String);
320
+ queryResults.value = rows;
321
+ if (resultColumns.value.length === 0 && rows.length > 0) resultColumns.value = Object.keys(rows[0] || {});
322
+ appendQueryHistory({
323
+ id: String(Date.now()),
324
+ type: getSqlType(sql),
325
+ sql,
326
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
327
+ executionTime: Date.now() - start,
328
+ status: "success",
329
+ connectionId,
330
+ connectionName,
331
+ isFavorite: false,
332
+ affectedRows: 0,
333
+ returnedRows: rows.length,
334
+ resultPreview: {
335
+ columns: resultColumns.value,
336
+ data: rows.slice(0, 5)
337
+ }
338
+ });
339
+ } catch (error) {
340
+ queryError.value = error?.msg || error?.message || t("explorer.sqlExecuteFailed");
341
+ appendQueryHistory({
342
+ id: String(Date.now()),
343
+ type: getSqlType(sql),
344
+ sql,
345
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
346
+ executionTime: Date.now() - start,
347
+ status: "failed",
348
+ connectionId,
349
+ connectionName,
350
+ isFavorite: false,
351
+ errorMessage: queryError.value
352
+ });
353
+ } finally {
354
+ isExecuting.value = false;
355
+ }
356
+ }
357
+ function formatSql() {
358
+ let formatted = querySql.value.replace(/\s+/g, " ").replace(/,/g, ",\n ").replace(/\bFROM\b/gi, "\nFROM").replace(/\bWHERE\b/gi, "\nWHERE").replace(/\bORDER BY\b/gi, "\nORDER BY").replace(/\bGROUP BY\b/gi, "\nGROUP BY").replace(/\bHAVING\b/gi, "\nHAVING").replace(/\bLIMIT\b/gi, "\nLIMIT").trim();
359
+ querySql.value = formatted;
360
+ }
361
+ function clearQuery() {
362
+ querySql.value = "";
363
+ queryError.value = "";
364
+ queryResults.value = [];
365
+ currentPage.value = 1;
366
+ }
367
+ function clearResults() {
368
+ queryResults.value = [];
369
+ resultColumns.value = [];
370
+ queryError.value = "";
371
+ }
372
+ function sortByColumn(column) {
373
+ if (sortColumn.value === column) sortDirection.value = sortDirection.value === "asc" ? "desc" : "asc";
374
+ else {
375
+ sortColumn.value = column;
376
+ sortDirection.value = "asc";
377
+ }
378
+ }
379
+ function exportResults() {
380
+ if (queryResults.value.length === 0) return;
381
+ const headers = {};
382
+ columns.value.forEach((col) => {
383
+ headers[col] = col;
384
+ });
385
+ exportDataToCSV(queryResults.value, headers, `query_results_${(/* @__PURE__ */ new Date()).getTime()}.csv`);
386
+ }
387
+ function formatCellValue(value) {
388
+ if (value === null || value === void 0) return "";
389
+ let strValue = String(value);
390
+ if (typeof value === "string") {
391
+ const trimmedValue = strValue.trim();
392
+ if (trimmedValue.startsWith("{") && trimmedValue.endsWith("}") || trimmedValue.startsWith("[") && trimmedValue.endsWith("]")) try {
393
+ const parsed = JSON.parse(trimmedValue);
394
+ const formatted = JSON.stringify(parsed, null, 2);
395
+ if (formatted.length > 50) return formatted.substring(0, 50) + "...";
396
+ return formatted;
397
+ } catch (e) {}
398
+ } else if (typeof value === "object") try {
399
+ const formatted = JSON.stringify(value, null, 2);
400
+ if (formatted.length > 50) return formatted.substring(0, 50) + "...";
401
+ return formatted;
402
+ } catch (e) {}
403
+ if (strValue.length > 50) return strValue.substring(0, 50) + "...";
404
+ return strValue;
405
+ }
406
+ function getSqlModeLabel() {
407
+ const sql = querySql.value.toUpperCase().trim();
408
+ if (sql.startsWith("SELECT")) return "SELECT";
409
+ if (sql.startsWith("INSERT")) return "INSERT";
410
+ if (sql.startsWith("UPDATE")) return "UPDATE";
411
+ if (sql.startsWith("DELETE")) return "DELETE";
412
+ if (sql.startsWith("CREATE")) return "CREATE";
413
+ if (sql.startsWith("DROP")) return "DROP";
414
+ if (sql.startsWith("ALTER")) return "ALTER";
415
+ return "SQL";
416
+ }
417
+ function saveQuery() {
418
+ showSaveDialog.value = true;
419
+ }
420
+ function closeSaveDialog() {
421
+ showSaveDialog.value = false;
422
+ queryName.value = "";
423
+ queryDescription.value = "";
424
+ }
425
+ function confirmSave() {
426
+ if (!queryName.value.trim()) return;
427
+ const record = {
428
+ id: String(Date.now()),
429
+ name: queryName.value.trim(),
430
+ description: queryDescription.value.trim(),
431
+ sql: querySql.value,
432
+ connectionId: String(selectedConnection.value || ""),
433
+ database: String(selectedDatabase.value || ""),
434
+ createdAt: (/* @__PURE__ */ new Date()).toISOString()
435
+ };
436
+ const next = [record, ...readPersisted(SAVED_QUERIES_KEY, "savedQueries").filter((item) => item?.name !== record.name)];
437
+ writePersisted(SAVED_QUERIES_KEY, "savedQueries", next.slice(0, 50));
438
+ loadSavedQueries();
439
+ closeSaveDialog();
440
+ }
441
+ async function loadSavedQuery(item) {
442
+ querySql.value = item.sql;
443
+ if (item.connectionId) {
444
+ selectedConnection.value = item.connectionId;
445
+ await loadDatabases();
446
+ }
447
+ if (item.database) selectedDatabase.value = item.database;
448
+ queryError.value = "";
449
+ nextTick(() => {
450
+ updateCursorInfo();
451
+ sqlEditor.value?.focus();
452
+ });
453
+ }
454
+ function nextPage() {
455
+ if (currentPage.value < totalPages.value) currentPage.value++;
456
+ }
457
+ function prevPage() {
458
+ if (currentPage.value > 1) currentPage.value--;
459
+ }
460
+ onMounted(async () => {
461
+ await loadConnections();
462
+ loadSavedQueries();
463
+ const sql = route.query.sql;
464
+ if (typeof sql === "string" && sql) querySql.value = sql;
465
+ const connectionId = route.query.connectionId;
466
+ if (typeof connectionId === "string" && connectionId) {
467
+ selectedConnection.value = connectionId;
468
+ await loadDatabases();
469
+ }
470
+ const database = route.query.database;
471
+ if (typeof database === "string" && database) selectedDatabase.value = database;
472
+ nextTick(() => updateCursorInfo());
473
+ });
474
+ watch(querySql, () => {
475
+ nextTick(() => {
476
+ updateCursorInfo();
477
+ });
478
+ });
479
+ return (_ctx, _cache) => {
480
+ return openBlock(), createElementBlock("div", _hoisted_1, [
481
+ createBaseVNode("div", _hoisted_2, [_cache[10] || (_cache[10] = createBaseVNode("div", { class: "query-title" }, [createBaseVNode("i", { class: "bi bi-terminal" }), createBaseVNode("span", null, "SQL查询编辑器")], -1)), createBaseVNode("div", _hoisted_3, [
482
+ withDirectives(createBaseVNode("select", {
483
+ "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => selectedConnection.value = $event),
484
+ class: "connection-select",
485
+ onChange: loadDatabases
486
+ }, [_cache[5] || (_cache[5] = createBaseVNode("option", { value: "" }, "选择数据库连接", -1)), (openBlock(true), createElementBlock(Fragment, null, renderList(connections.value, (connection) => {
487
+ return openBlock(), createElementBlock("option", {
488
+ key: connection.id,
489
+ value: connection.id
490
+ }, toDisplayString(connection.name), 9, _hoisted_4);
491
+ }), 128))], 544), [[vModelSelect, selectedConnection.value]]),
492
+ withDirectives(createBaseVNode("select", {
493
+ "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => selectedDatabase.value = $event),
494
+ class: "connection-select database-select"
495
+ }, [createBaseVNode("option", _hoisted_5, toDisplayString(_ctx.$t("sqlQueryEditor.defaultDatabase")), 1), (openBlock(true), createElementBlock(Fragment, null, renderList(databases.value, (database) => {
496
+ return openBlock(), createElementBlock("option", {
497
+ key: database,
498
+ value: database
499
+ }, toDisplayString(database), 9, _hoisted_6);
500
+ }), 128))], 512), [[vModelSelect, selectedDatabase.value]]),
501
+ createBaseVNode("button", {
502
+ class: "btn-run",
503
+ onClick: executeQuery,
504
+ disabled: !querySql.value || !selectedConnection.value || isExecuting.value
505
+ }, [..._cache[6] || (_cache[6] = [createBaseVNode("i", { class: "bi bi-play-fill" }, null, -1), createBaseVNode("span", null, "执行", -1)])], 8, _hoisted_7),
506
+ createBaseVNode("button", {
507
+ class: "btn-format",
508
+ onClick: formatSql,
509
+ disabled: !querySql.value
510
+ }, [..._cache[7] || (_cache[7] = [createBaseVNode("i", { class: "bi bi-code-slash" }, null, -1), createBaseVNode("span", null, "格式化", -1)])], 8, _hoisted_8),
511
+ createBaseVNode("button", {
512
+ class: "btn-clear",
513
+ onClick: clearQuery
514
+ }, [..._cache[8] || (_cache[8] = [createBaseVNode("i", { class: "bi bi-trash" }, null, -1), createBaseVNode("span", null, "清空", -1)])]),
515
+ createBaseVNode("button", {
516
+ class: "btn-save",
517
+ onClick: saveQuery,
518
+ disabled: !querySql.value
519
+ }, [..._cache[9] || (_cache[9] = [createBaseVNode("i", { class: "bi bi-save" }, null, -1), createBaseVNode("span", null, "保存", -1)])], 8, _hoisted_9)
520
+ ])]),
521
+ savedQueries.value.length > 0 ? (openBlock(), createElementBlock("div", _hoisted_10, [createBaseVNode("span", _hoisted_11, toDisplayString(_ctx.$t("sqlQueryEditor.savedQueries")), 1), (openBlock(true), createElementBlock(Fragment, null, renderList(savedQueries.value, (item) => {
522
+ return openBlock(), createElementBlock("button", {
523
+ key: item.id,
524
+ class: "saved-query-chip",
525
+ title: item.description || item.sql,
526
+ onClick: ($event) => loadSavedQuery(item)
527
+ }, [_cache[11] || (_cache[11] = createBaseVNode("i", { class: "bi bi-file-code" }, null, -1)), createBaseVNode("span", null, toDisplayString(item.name), 1)], 8, _hoisted_12);
528
+ }), 128))])) : createCommentVNode("", true),
529
+ createBaseVNode("div", _hoisted_13, [createBaseVNode("div", _hoisted_14, [createBaseVNode("div", _hoisted_15, [(openBlock(true), createElementBlock(Fragment, null, renderList(sqlSnippets.value, (snippet) => {
530
+ return openBlock(), createElementBlock("button", {
531
+ key: snippet.name,
532
+ class: "snippet-btn",
533
+ onClick: ($event) => insertSnippet(snippet),
534
+ title: snippet.description
535
+ }, [createBaseVNode("i", { class: normalizeClass(snippet.icon) }, null, 2), createBaseVNode("span", null, toDisplayString(snippet.name), 1)], 8, _hoisted_16);
536
+ }), 128))]), createBaseVNode("div", _hoisted_17, [createBaseVNode("span", _hoisted_18, "行: " + toDisplayString(currentLine.value) + ", 列: " + toDisplayString(currentColumn.value), 1), createBaseVNode("span", _hoisted_19, toDisplayString(getSqlModeLabel()), 1)])]), createBaseVNode("div", _hoisted_20, [withDirectives(createBaseVNode("textarea", {
537
+ ref_key: "sqlEditor",
538
+ ref: sqlEditor,
539
+ "onUpdate:modelValue": _cache[2] || (_cache[2] = ($event) => querySql.value = $event),
540
+ class: "sql-editor",
541
+ placeholder: "在此输入SQL查询语句...",
542
+ onInput: handleInput,
543
+ onKeydown: handleKeydown,
544
+ onScroll: syncScroll,
545
+ spellcheck: "false"
546
+ }, null, 544), [[vModelText, querySql.value]]), createBaseVNode("div", {
547
+ class: "line-numbers",
548
+ ref_key: "lineNumbers",
549
+ ref: lineNumbers,
550
+ onScroll: syncScroll
551
+ }, [(openBlock(true), createElementBlock(Fragment, null, renderList(lineCount.value, (line) => {
552
+ return openBlock(), createElementBlock("div", {
553
+ key: line,
554
+ class: normalizeClass(["line-number", { "current-line": line === currentLine.value }])
555
+ }, toDisplayString(line), 3);
556
+ }), 128))], 544)])]),
557
+ resultColumns.value.length > 0 || queryResults.value.length > 0 || queryError.value ? (openBlock(), createElementBlock("div", _hoisted_21, [createBaseVNode("div", _hoisted_22, [createBaseVNode("div", _hoisted_23, [
558
+ _cache[12] || (_cache[12] = createBaseVNode("i", { class: "bi bi-table" }, null, -1)),
559
+ _cache[13] || (_cache[13] = createBaseVNode("span", null, "查询结果", -1)),
560
+ resultColumns.value.length > 0 || queryResults.value.length > 0 ? (openBlock(), createElementBlock("span", _hoisted_24, " (" + toDisplayString(queryResults.value.length) + " 行) ", 1)) : createCommentVNode("", true)
561
+ ]), createBaseVNode("div", _hoisted_25, [queryResults.value.length > 0 ? (openBlock(), createElementBlock("button", {
562
+ key: 0,
563
+ class: "btn-export",
564
+ onClick: exportResults
565
+ }, [..._cache[14] || (_cache[14] = [createBaseVNode("i", { class: "bi bi-download" }, null, -1), createBaseVNode("span", null, "导出", -1)])])) : createCommentVNode("", true), createBaseVNode("button", {
566
+ class: "btn-clear-results",
567
+ onClick: clearResults
568
+ }, [..._cache[15] || (_cache[15] = [createBaseVNode("i", { class: "bi bi-x-lg" }, null, -1), createBaseVNode("span", null, "清除", -1)])])])]), createBaseVNode("div", _hoisted_26, [queryError.value ? (openBlock(), createElementBlock("div", _hoisted_27, [_cache[17] || (_cache[17] = createBaseVNode("i", { class: "bi bi-exclamation-triangle" }, null, -1)), createBaseVNode("div", null, [_cache[16] || (_cache[16] = createBaseVNode("strong", null, "查询错误:", -1)), createBaseVNode("p", null, toDisplayString(queryError.value), 1)])])) : (openBlock(), createElementBlock("div", _hoisted_28, [createBaseVNode("table", _hoisted_29, [createBaseVNode("thead", null, [createBaseVNode("tr", null, [(openBlock(true), createElementBlock(Fragment, null, renderList(columns.value, (column) => {
569
+ return openBlock(), createElementBlock("th", {
570
+ key: column,
571
+ onClick: ($event) => sortByColumn(column)
572
+ }, [createTextVNode(toDisplayString(column) + " ", 1), sortColumn.value === column ? (openBlock(), createElementBlock("i", _hoisted_31)) : createCommentVNode("", true)], 8, _hoisted_30);
573
+ }), 128))])]), createBaseVNode("tbody", null, [(openBlock(true), createElementBlock(Fragment, null, renderList(paginatedResults.value, (row, index) => {
574
+ return openBlock(), createElementBlock("tr", { key: index }, [(openBlock(true), createElementBlock(Fragment, null, renderList(columns.value, (column) => {
575
+ return openBlock(), createElementBlock("td", {
576
+ key: column,
577
+ title: formatCellValue(row[column])
578
+ }, toDisplayString(formatCellValue(row[column])), 9, _hoisted_32);
579
+ }), 128))]);
580
+ }), 128)), paginatedResults.value.length === 0 ? (openBlock(), createElementBlock("tr", _hoisted_33, [createBaseVNode("td", {
581
+ colspan: columns.value.length || 1,
582
+ class: "no-results"
583
+ }, toDisplayString(_ctx.$t("common.noData")), 9, _hoisted_34)])) : createCommentVNode("", true)])]), totalPages.value > 1 ? (openBlock(), createElementBlock("div", _hoisted_35, [
584
+ createBaseVNode("button", {
585
+ onClick: prevPage,
586
+ disabled: currentPage.value === 1
587
+ }, [..._cache[18] || (_cache[18] = [createBaseVNode("i", { class: "bi bi-chevron-left" }, null, -1)])], 8, _hoisted_36),
588
+ createBaseVNode("span", _hoisted_37, toDisplayString(currentPage.value) + " / " + toDisplayString(totalPages.value), 1),
589
+ createBaseVNode("button", {
590
+ onClick: nextPage,
591
+ disabled: currentPage.value === totalPages.value
592
+ }, [..._cache[19] || (_cache[19] = [createBaseVNode("i", { class: "bi bi-chevron-right" }, null, -1)])], 8, _hoisted_38)
593
+ ])) : createCommentVNode("", true)]))])])) : createCommentVNode("", true),
594
+ showSaveDialog.value ? (openBlock(), createElementBlock("div", _hoisted_39, [createBaseVNode("div", _hoisted_40, [
595
+ createBaseVNode("div", { class: "modal-header" }, [_cache[21] || (_cache[21] = createBaseVNode("h3", null, "保存SQL查询", -1)), createBaseVNode("button", {
596
+ class: "modal-close",
597
+ onClick: closeSaveDialog
598
+ }, [..._cache[20] || (_cache[20] = [createBaseVNode("i", { class: "bi bi-x-lg" }, null, -1)])])]),
599
+ createBaseVNode("div", _hoisted_41, [createBaseVNode("div", _hoisted_42, [_cache[22] || (_cache[22] = createBaseVNode("label", null, "查询名称", -1)), withDirectives(createBaseVNode("input", {
600
+ "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => queryName.value = $event),
601
+ type: "text",
602
+ placeholder: "输入查询名称",
603
+ class: "form-input"
604
+ }, null, 512), [[vModelText, queryName.value]])]), createBaseVNode("div", _hoisted_43, [_cache[23] || (_cache[23] = createBaseVNode("label", null, "描述", -1)), withDirectives(createBaseVNode("textarea", {
605
+ "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => queryDescription.value = $event),
606
+ placeholder: "输入查询描述",
607
+ class: "form-textarea",
608
+ rows: "3"
609
+ }, null, 512), [[vModelText, queryDescription.value]])])]),
610
+ createBaseVNode("div", _hoisted_44, [createBaseVNode("button", {
611
+ class: "btn-cancel",
612
+ onClick: closeSaveDialog
613
+ }, "取消"), createBaseVNode("button", {
614
+ class: "btn-confirm",
615
+ onClick: confirmSave,
616
+ disabled: !queryName.value
617
+ }, "保存", 8, _hoisted_45)])
618
+ ])])) : createCommentVNode("", true)
619
+ ]);
620
+ };
621
+ }
622
+ });
623
+ }));
624
+ //#endregion
625
+ //#region src/platform/database/components/sql-query-editor.vue?vue&type=style&index=0&scoped=9923949f&lang.css
626
+ var init_sql_query_editor_vue_vue_type_style_index_0_scoped_9923949f_lang = __esmMin((() => {}));
627
+ //#endregion
628
+ //#region src/platform/database/components/sql-query-editor.vue
629
+ var sql_query_editor_default;
630
+ //#endregion
631
+ __esmMin((() => {
632
+ init_sql_query_editor_vue_vue_type_script_setup_true_lang();
633
+ init_sql_query_editor_vue_vue_type_script_setup_true_lang();
634
+ init_sql_query_editor_vue_vue_type_style_index_0_scoped_9923949f_lang();
635
+ init__plugin_vue_export_helper();
636
+ sql_query_editor_default = /*#__PURE__*/ _plugin_vue_export_helper_default(sql_query_editor_vue_vue_type_script_setup_true_lang_default, [["__scopeId", "data-v-9923949f"]]);
637
+ }))();
638
+ export { sql_query_editor_default as default };