Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

feat(sql-file): add option to choose whether to close dialog on execution (#12891) (#12919)

lxk9558c15bd100461
diff --git a/apps/desktop/src/components/sql-file/SqlFileExecutionDialog.retry.spec.ts b/apps/desktop/src/components/sql-file/SqlFileExecutionDialog.retry.spec.ts
index 1b1135888c..a68e535b27 100644
--- a/apps/desktop/src/components/sql-file/SqlFileExecutionDialog.retry.spec.ts
+++ b/apps/desktop/src/components/sql-file/SqlFileExecutionDialog.retry.spec.ts
@@ -1217,3 +1217,58 @@ describe("SqlFileExecutionDialog completion prompt and close (#12608)", () => {
expect(onOpenChange).toHaveBeenCalledWith(false);
});
});
+
+describe("SqlFileExecutionDialog closeOnSuccess option (#12891)", () => {
+ it("toggles closeOnSuccess option and updates localStorage", async () => {
+ await mountReadyDialog();
+ expect(localStorage.getItem("dbx-sql-file-close-on-success")).toBeNull();
+
+ const toggleButton = findButton("sqlFile.closeOnSuccess");
+ toggleButton.click();
+ await nextTick();
+
+ expect(localStorage.getItem("dbx-sql-file-close-on-success")).toBe("false");
+
+ toggleButton.click();
+ await nextTick();
+
+ expect(localStorage.getItem("dbx-sql-file-close-on-success")).toBe("true");
+ });
+
+ it("keeps dialog open after successful execution when closeOnSuccess is false", async () => {
+ localStorage.setItem("dbx-sql-file-close-on-success", "false");
+ const onOpenChange = vi.fn();
+ await mountReadyDialog(onOpenChange);
+
+ mocks.executeSqlFiles.mockImplementationOnce(async (request) => {
+ mocks.progressHandler?.(progress(request.executionId, "done", { statementIndex: 1, successCount: 1, failureCount: 0 }));
+ });
+
+ findButton("sqlFile.execute").click();
+
+ await vi.waitFor(() => expect(mocks.toast).toHaveBeenCalledWith("sqlFile.executeSuccess", 3000));
+ expect(onOpenChange).not.toHaveBeenCalled();
+ expect(findButton("sqlFile.execute").disabled).toBe(false);
+ });
+
+ it("keeps dialog open after manual transaction commit when closeOnSuccess is false", async () => {
+ localStorage.setItem("dbx-sql-file-close-on-success", "false");
+ const onOpenChange = vi.fn();
+ await mountReadyDialog(onOpenChange);
+ const label = Array.from(root!.querySelectorAll("label")).find((item) => item.textContent?.includes("toolbar.manualTransaction"));
+ label!.querySelector<HTMLInputElement>('input[type="checkbox"]')!.click();
+ await nextTick();
+
+ mocks.executeSqlFiles.mockImplementationOnce(async (request: { executionId: string }) => {
+ mocks.progressHandler?.(progress(request.executionId, "done", { statementIndex: 1, successCount: 1, failureCount: 0 }));
+ });
+ findButton("sqlFile.execute").click();
+
+ await vi.waitFor(() => expect(findButton("toolbar.commit").disabled).toBe(false));
+ expect(onOpenChange).not.toHaveBeenCalled();
+
+ findButton("toolbar.commit").click();
+ await vi.waitFor(() => expect(mocks.toast).toHaveBeenCalledWith("sqlFile.executeSuccess", 3000));
+ expect(onOpenChange).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/desktop/src/components/sql-file/SqlFileExecutionDialog.vue b/apps/desktop/src/components/sql-file/SqlFileExecutionDialog.vue
index 0c54528c90..4ba6cffafa 100644
--- a/apps/desktop/src/components/sql-file/SqlFileExecutionDialog.vue
+++ b/apps/desktop/src/components/sql-file/SqlFileExecutionDialog.vue
@@ -48,6 +48,7 @@ import { parseSqlFilePathInput } from "./sqlFilePathInput";
import { orderConnectionsForSidebarDisplay } from "@/lib/sidebar/connectionListSort";
import SqlFileProgressIndicator from "./SqlFileProgressIndicator.vue";
import { useExportTracker, type ExportTask } from "@/composables/useExportTracker";
+import { readSqlFileCloseOnSuccess, writeSqlFileCloseOnSuccess } from "@/lib/sql/sqlFileExecutionOptions";
import { translateBackendError } from "@/i18n/backend-errors";
import { Check, CheckSquare, FileCode, FolderOpen, Loader2, Play, Square, X } from "@lucide/vue";
@@ -148,6 +149,10 @@ const loadingDatabases = ref(false);
const preferredTarget = ref<ExternalSqlFileTarget>();
const continueOnError = ref(false);
const skipRelationalConstraints = ref(false);
+const closeOnSuccess = ref(readSqlFileCloseOnSuccess());
+watch(closeOnSuccess, (enabled) => {
+ writeSqlFileCloseOnSuccess(enabled);
+});
const manualTransaction = ref(false);
const txnSessionId = ref<string>();
const commitUncertain = ref(false);
@@ -258,7 +263,9 @@ async function finishTransaction(commit: boolean) {
toast(t("sqlFile.completedWithErrors", { succeeded: progress.value?.successCount ?? 0, failed: failureCount }), 5000);
} else {
toast(t("sqlFile.executeSuccess"), 3000);
- open.value = false;
+ if (closeOnSuccess.value) {
+ open.value = false;
+ }
}
}
return true;
@@ -525,6 +532,7 @@ function resetState() {
continueOnError.value = false;
skipRelationalConstraints.value = false;
manualTransaction.value = false;
+ closeOnSuccess.value = readSqlFileCloseOnSuccess();
restoreSelectedTables.value = false;
resetExecution();
}
@@ -892,7 +900,9 @@ async function startExecution() {
toast(t("sqlFile.completedWithErrors", { succeeded: finalProgress?.successCount ?? 0, failed: failureCount }), 5000);
} else {
toast(t("sqlFile.executeSuccess"), 3000);
- open.value = false;
+ if (closeOnSuccess.value) {
+ open.value = false;
+ }
}
}
}
@@ -1167,6 +1177,11 @@ watch(
<Square v-else class="w-3.5 h-3.5 text-muted-foreground/40 shrink-0" />
{{ t("sqlFile.skipRelationalConstraints") }}
</button>
+ <button type="button" class="flex items-center gap-2 text-xs text-left" :disabled="executionLocked" @click="closeOnSuccess = !closeOnSuccess">
+ <CheckSquare v-if="closeOnSuccess" class="w-3.5 h-3.5 text-primary shrink-0" />
+ <Square v-else class="w-3.5 h-3.5 text-muted-foreground/40 shrink-0" />
+ {{ t("sqlFile.closeOnSuccess") }}
+ </button>
</div>
<div v-if="running || terminalStatus !== 'idle' || progress" class="min-w-0 space-y-3">
diff --git a/apps/desktop/src/i18n/locales/az.ts b/apps/desktop/src/i18n/locales/az.ts
index 8e645bce5a..58f7efc270 100644
--- a/apps/desktop/src/i18n/locales/az.ts
+++ b/apps/desktop/src/i18n/locales/az.ts
@@ -6849,6 +6849,7 @@ export default withEnglishFallback({
options: "Seçimlər",
packageParts: "{count} SQL hissəsi",
skipRelationalConstraints: "İdxal zamanı əlaqəli məhdudiyyətləri müvəqqəti söndür",
+ closeOnSuccess: "Tamamlandıqda dialoqu bağla",
continueOnError: "Xəta olduqda davam et",
runInBackground: "Arxa planda işlət",
cancelling: "Ləğv edilir...",
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index 56cc2a5dc6..719782743a 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -8384,6 +8384,7 @@ export default {
options: "Options",
continueOnError: "Continue on error",
skipRelationalConstraints: "Temporarily disable relational constraints during import",
+ closeOnSuccess: "Close dialog on completion",
packageParts: "{count} SQL parts",
runInBackground: "Run in background",
cancelling: "Cancelling...",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index a9a25b3f91..64d150869b 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -7503,6 +7503,7 @@ export default withEnglishFallback({
options: "Opciones",
packageParts: "{count} partes SQL",
skipRelationalConstraints: "Desactivar temporalmente las restricciones relacionales durante la importación",
+ closeOnSuccess: "Cerrar cuadro de diálogo al finalizar",
continueOnError: "Continuar en caso de error",
runInBackground: "Ejecutar en segundo plano",
cancelling: "Cancelando...",
diff --git a/apps/desktop/src/i18n/locales/id.ts b/apps/desktop/src/i18n/locales/id.ts
index ab9e3d3b21..454270772b 100644
--- a/apps/desktop/src/i18n/locales/id.ts
+++ b/apps/desktop/src/i18n/locales/id.ts
@@ -7539,6 +7539,7 @@ export default withEnglishFallback({
options: "Opsi",
continueOnError: "Lanjutkan jika terjadi galat",
skipRelationalConstraints: "Nonaktifkan sementara batasan relasional selama impor",
+ closeOnSuccess: "Tutup dialog setelah selesai",
packageParts: "{count} bagian SQL",
runInBackground: "Jalankan di latar belakang",
cancelling: "Membatalkan...",
diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts
index ac444260a9..5a47d24cf6 100644
--- a/apps/desktop/src/i18n/locales/it.ts
+++ b/apps/desktop/src/i18n/locales/it.ts
@@ -7296,6 +7296,7 @@ export default withEnglishFallback({
options: "Opzioni",
packageParts: "{count} parti SQL",
skipRelationalConstraints: "Disattiva temporaneamente i vincoli relazionali durante l'importazione",
+ closeOnSuccess: "Chiudi finestra di dialogo al completamento",
continueOnError: "Continua in caso di errore",
runInBackground: "Esegui in background",
cancelling: "Annullamento in corso...",
diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.ts
index 07fd5b1bda..b667a6b5f8 100644
--- a/apps/desktop/src/i18n/locales/ja.ts
+++ b/apps/desktop/src/i18n/locales/ja.ts
@@ -7325,6 +7325,7 @@ export default withEnglishFallback({
options: "オプション",
packageParts: "{count} 個のSQLパート",
skipRelationalConstraints: "インポート中に関連性制約を一時的に無効化",
+ closeOnSuccess: "実行完了後にダイアログを閉じる",
continueOnError: "エラー時に続行",
cancelling: "キャンセル中...",
cancel: "キャンセル",
diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.ts
index 097d89f21f..97c8d1dec8 100644
--- a/apps/desktop/src/i18n/locales/ko.ts
+++ b/apps/desktop/src/i18n/locales/ko.ts
@@ -7192,6 +7192,7 @@ export default withEnglishFallback({
options: "옵션",
packageParts: "SQL 파트 {count}개",
skipRelationalConstraints: "가져오기 중 관계형 제약 조건을 일시적으로 해제",
+ closeOnSuccess: "실행 완료 후 대화상자 닫기",
continueOnError: "오류 시 계속",
runInBackground: "백그라운드에서 실행",
cancelling: "취소하는 중...",
diff --git a/apps/desktop/src/i18n/locales/pl.ts b/apps/desktop/src/i18n/locales/pl.ts
index c402681d53..f1b73d6b1d 100644
--- a/apps/desktop/src/i18n/locales/pl.ts
+++ b/apps/desktop/src/i18n/locales/pl.ts
@@ -7595,6 +7595,7 @@ export default withEnglishFallback({
options: "Opcje",
continueOnError: "Kontynuuj po błędzie",
skipRelationalConstraints: "Tymczasowo wyłącz więzy integralności relacyjnej podczas importu",
+ closeOnSuccess: "Zamknij okno po zakończeniu",
packageParts: "Części SQL: {count}",
runInBackground: "Uruchom w tle",
cancelling: "Anulowanie...",
diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts
index d187eb82c5..5c4e5c7253 100644
--- a/apps/desktop/src/i18n/locales/pt-BR.ts
+++ b/apps/desktop/src/i18n/locales/pt-BR.ts
@@ -7295,6 +7295,7 @@ export default withEnglishFallback({
options: "Opções",
packageParts: "{count} partes SQL",
skipRelationalConstraints: "Desabilitar temporariamente restrições relacionais durante a importação",
+ closeOnSuccess: "Fechar diálogo ao concluir",
continueOnError: "Continuar em caso de erro",
runInBackground: "Executar em segundo plano",
cancelling: "Cancelando...",
diff --git a/apps/desktop/src/i18n/locales/ru.ts b/apps/desktop/src/i18n/locales/ru.ts
index 301540df40..eb56e48fb9 100644
--- a/apps/desktop/src/i18n/locales/ru.ts
+++ b/apps/desktop/src/i18n/locales/ru.ts
@@ -8630,6 +8630,7 @@ export default withEnglishFallback({
options: "Параметры",
continueOnError: "Продолжать при ошибке",
skipRelationalConstraints: "Временно отключить реляционные ограничения во время импорта",
+ closeOnSuccess: "Закрывать диалоговое окно после завершения",
packageParts: "{count} частей SQL",
runInBackground: "Выполнять в фоне",
cancelling: "Отмена...",
diff --git a/apps/desktop/src/i18n/locales/th.ts b/apps/desktop/src/i18n/locales/th.ts
index 17ba898517..1d3f28c16f 100644
--- a/apps/desktop/src/i18n/locales/th.ts
+++ b/apps/desktop/src/i18n/locales/th.ts
@@ -9027,6 +9027,7 @@ export default withEnglishFallback({
options: "Options",
continueOnError: "ดำเนินการต่อเมื่อเกิดข้อผิดพลาด",
skipRelationalConstraints: "ปิดใช้ข้อจำกัดเชิงสัมพันธ์ชั่วคราวระหว่างการนำเข้า",
+ closeOnSuccess: "ปิดกล่องโต้ตอบเมื่อเสร็จสิ้น",
packageParts: "ส่วน SQL จำนวน {count} ส่วน",
runInBackground: "ทำงานเบื้องหลัง",
cancelling: "กำลังยกเลิก…",
diff --git a/apps/desktop/src/i18n/locales/tr.ts b/apps/desktop/src/i18n/locales/tr.ts
index 48509d8843..3d73c65f08 100644
--- a/apps/desktop/src/i18n/locales/tr.ts
+++ b/apps/desktop/src/i18n/locales/tr.ts
@@ -6729,6 +6729,7 @@ export default withEnglishFallback({
options: "Seçenekler",
packageParts: "{count} SQL bölümü",
skipRelationalConstraints: "İçe aktarma sırasında ilişkisel kısıtlamaları geçici olarak devre dışı bırak",
+ closeOnSuccess: "Tamamlandığında iletişim kutusunu kapat",
continueOnError: "Hatada devam et",
runInBackground: "Arka planda çalıştır",
cancelling: "İptal ediliyor...",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index d894131e42..7f864a1a59 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -8352,6 +8352,7 @@ export default withEnglishFallback({
options: "选项",
packageParts: "{count} 个 SQL 分片",
skipRelationalConstraints: "导入期间临时禁用关系约束",
+ closeOnSuccess: "执行完成后关闭弹窗",
continueOnError: "出错后继续",
runInBackground: "后台运行",
cancelling: "正在取消...",
diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts
index a209fbcd81..7cd8821be9 100644
--- a/apps/desktop/src/i18n/locales/zh-TW.ts
+++ b/apps/desktop/src/i18n/locales/zh-TW.ts
@@ -6634,6 +6634,7 @@ export default withEnglishFallback({
options: "選項",
packageParts: "{count} 個 SQL 分片",
skipRelationalConstraints: "匯入期間暫時停用關聯式約束",
+ closeOnSuccess: "執行完成後關閉彈窗",
continueOnError: "錯誤後繼續",
cancelling: "正在取消……",
cancel: "取消",
diff --git a/apps/desktop/src/lib/sql/__tests__/sqlFileExecutionOptions.spec.ts b/apps/desktop/src/lib/sql/__tests__/sqlFileExecutionOptions.spec.ts
new file mode 100644
index 0000000000..871d382d0e
--- /dev/null
+++ b/apps/desktop/src/lib/sql/__tests__/sqlFileExecutionOptions.spec.ts
@@ -0,0 +1,71 @@
+import { describe, expect, it } from "vitest";
+import { SQL_FILE_CLOSE_ON_SUCCESS_STORAGE_KEY, readSqlFileCloseOnSuccess, writeSqlFileCloseOnSuccess } from "../sqlFileExecutionOptions";
+
+describe("sqlFileExecutionOptions", () => {
+ function createMockStorage(initial: Record<string, string> = {}): Storage {
+ const store = new Map<string, string>(Object.entries(initial));
+ return {
+ getItem: (key: string) => store.get(key) ?? null,
+ setItem: (key: string, value: string) => store.set(key, value),
+ removeItem: (key: string) => store.delete(key),
+ clear: () => store.clear(),
+ key: (index: number) => Array.from(store.keys())[index] ?? null,
+ get length() {
+ return store.size;
+ },
+ };
+ }
+
+ describe("readSqlFileCloseOnSuccess", () => {
+ it("defaults to true when storage is unpopulated", () => {
+ const storage = createMockStorage();
+ expect(readSqlFileCloseOnSuccess(storage)).toBe(true);
+ });
+
+ it("defaults to true when storage is undefined", () => {
+ expect(readSqlFileCloseOnSuccess(undefined)).toBe(true);
+ });
+
+ it("returns true when stored value is true", () => {
+ const storage = createMockStorage({ [SQL_FILE_CLOSE_ON_SUCCESS_STORAGE_KEY]: "true" });
+ expect(readSqlFileCloseOnSuccess(storage)).toBe(true);
+ });
+
+ it("returns false when stored value is false", () => {
+ const storage = createMockStorage({ [SQL_FILE_CLOSE_ON_SUCCESS_STORAGE_KEY]: "false" });
+ expect(readSqlFileCloseOnSuccess(storage)).toBe(false);
+ });
+
+ it("falls back to true when storage throws an exception", () => {
+ const errorStorage = {
+ getItem: () => {
+ throw new Error("SecurityError: access denied");
+ },
+ } as unknown as Storage;
+ expect(readSqlFileCloseOnSuccess(errorStorage)).toBe(true);
+ });
+ });
+
+ describe("writeSqlFileCloseOnSuccess", () => {
+ it("persists true to storage", () => {
+ const storage = createMockStorage();
+ writeSqlFileCloseOnSuccess(true, storage);
+ expect(storage.getItem(SQL_FILE_CLOSE_ON_SUCCESS_STORAGE_KEY)).toBe("true");
+ });
+
+ it("persists false to storage", () => {
+ const storage = createMockStorage();
+ writeSqlFileCloseOnSuccess(false, storage);
+ expect(storage.getItem(SQL_FILE_CLOSE_ON_SUCCESS_STORAGE_KEY)).toBe("false");
+ });
+
+ it("gracefully catches storage exceptions", () => {
+ const errorStorage = {
+ setItem: () => {
+ throw new Error("QuotaExceededError");
+ },
+ } as unknown as Storage;
+ expect(() => writeSqlFileCloseOnSuccess(false, errorStorage)).not.toThrow();
+ });
+ });
+});
diff --git a/apps/desktop/src/lib/sql/sqlFileExecutionOptions.ts b/apps/desktop/src/lib/sql/sqlFileExecutionOptions.ts
new file mode 100644
index 0000000000..0bff4ca45d
--- /dev/null
+++ b/apps/desktop/src/lib/sql/sqlFileExecutionOptions.ts
@@ -0,0 +1,29 @@
+/**
+ * Persistence and retrieval for SQL file execution dialog options.
+ */
+
+export const SQL_FILE_CLOSE_ON_SUCCESS_STORAGE_KEY = "dbx-sql-file-close-on-success";
+
+/**
+ * Returns whether the SQL file execution dialog should close on successful completion.
+ * Defaults to true if unconfigured.
+ */
+export function readSqlFileCloseOnSuccess(storage: Storage | undefined = typeof localStorage === "undefined" ? undefined : localStorage): boolean {
+ try {
+ const stored = storage?.getItem(SQL_FILE_CLOSE_ON_SUCCESS_STORAGE_KEY);
+ return stored === null || stored === undefined ? true : stored === "true";
+ } catch {
+ return true;
+ }
+}
+
+/**
+ * Persists the close-on-success preference for SQL file execution.
+ */
+export function writeSqlFileCloseOnSuccess(enabled: boolean, storage: Storage | undefined = typeof localStorage === "undefined" ? undefined : localStorage): void {
+ try {
+ storage?.setItem(SQL_FILE_CLOSE_ON_SUCCESS_STORAGE_KEY, enabled ? "true" : "false");
+ } catch {
+ // Ignore storage quota or access errors.
+ }
+}