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。

fix(redis): disable SQL formatting for Redis queries

jearhea535cf8f5126
diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue
index c0429dca92..d3a3ff3c21 100644
--- a/apps/desktop/src/App.vue
+++ b/apps/desktop/src/App.vue
@@ -1410,6 +1410,9 @@ function resolveToolbarTab(tabId?: string) {
function formatActiveSql(tabId?: string) {
const tab = resolveToolbarTab(tabId);
if (!tab || tab.mode !== "query" || !tab.sql.trim()) return;
+ const connection = connectionStore.getConfig(tab.connectionId);
+ const databaseType = effectiveDatabaseTypeForConnection(connection) ?? connection?.db_type;
+ if (!canFormatSqlForDatabaseType(databaseType)) return;
formatSqlRequest.value = {
id: (formatSqlRequest.value?.id ?? 0) + 1,
tabId: tab.id,
diff --git a/apps/desktop/src/components/layout/EditorToolbar.vue b/apps/desktop/src/components/layout/EditorToolbar.vue
index 84350a7988..bacace8ca6 100644
--- a/apps/desktop/src/components/layout/EditorToolbar.vue
+++ b/apps/desktop/src/components/layout/EditorToolbar.vue
@@ -25,6 +25,7 @@ import { productionContextForDatabase } from "@/lib/database/productionSafety";
import { formatShortcutDisplay } from "@/lib/editor/shortcutDisplay";
import { resolveNextEditorToolbarTier, type EditorToolbarTier } from "@/lib/tabs/editorToolbarLayout";
import { looksLikeDmlStatement } from "@/lib/sql/dmlChangePreview";
+import { canFormatSqlForDatabaseType } from "@/lib/sql/sqlFormatter";
import type { QueryTab, ConnectionConfig } from "@/types/database";
const props = defineProps<{
@@ -326,7 +327,8 @@ const isActiveDatabaseDefault = computed(() => isDefaultDatabase(props.activeCon
// tier contract.
const showOverflowMenu = computed(() => toolbarTier.value >= 1);
-const showFormatButton = computed(() => toolbarTier.value < 2);
+const canFormatSql = computed(() => canFormatSqlForDatabaseType(props.activeConnection?.db_type));
+const showFormatButton = computed(() => canFormatSql.value && toolbarTier.value < 2);
const showExplainAnalyzeToggle = computed(() => toolbarTier.value < 3);
const showCompressButton = computed(() => toolbarTier.value < 1);
const showKeywordCaseButton = computed(() => toolbarTier.value < 1);
@@ -608,7 +610,7 @@ async function changeCatalog(selectedCatalog: string) {
{{ insertValueHintsToggleTooltip }}
</DropdownMenuCheckboxItem>
<template v-if="toolbarTier >= 2">
- <DropdownMenuItem :disabled="activeTab.isExecuting || activeTab.isExplaining || !activeTab.sql.trim()" @select="emit('formatSql')">
+ <DropdownMenuItem v-if="canFormatSql" :disabled="activeTab.isExecuting || activeTab.isExplaining || !activeTab.sql.trim()" @select="emit('formatSql')">
<AlignLeft class="h-3.5 w-3.5" />
{{ t("toolbar.formatSql") }}
</DropdownMenuItem>
diff --git a/apps/desktop/src/components/layout/__tests__/EditorToolbar.mount.spec.ts b/apps/desktop/src/components/layout/__tests__/EditorToolbar.mount.spec.ts
index 4216db16bd..3a5b7f9f77 100644
--- a/apps/desktop/src/components/layout/__tests__/EditorToolbar.mount.spec.ts
+++ b/apps/desktop/src/components/layout/__tests__/EditorToolbar.mount.spec.ts
@@ -141,6 +141,54 @@ describe("EditorToolbar mount contract", () => {
host.remove();
});
+ it("does not expose SQL formatting for Redis connections", async () => {
+ const connectionStore = useConnectionStore();
+ connectionStore.connections = [
+ {
+ id: "conn-redis",
+ name: "redis",
+ db_type: "redis",
+ host: "localhost",
+ port: 6379,
+ } as never,
+ ];
+
+ const host = createHost();
+ const app = createApp(EditorToolbar, {
+ activeTab: {
+ id: "tab-redis",
+ title: "Redis",
+ connectionId: "conn-redis",
+ database: "0",
+ sql: 'SET user:1 "hello world"',
+ mode: "query",
+ isExecuting: false,
+ isCancelling: false,
+ isExplaining: false,
+ },
+ activeConnection: connectionStore.getConfig("conn-redis"),
+ executableSql: 'SET user:1 "hello world"',
+ explainMode: "explain",
+ blockDangerousRedisCommands: true,
+ sqlKeywordCase: "preserve",
+ databaseRequiredSignal: 0,
+ autoCommit: true,
+ txnSessionId: undefined,
+ txnAutoRolledBack: false,
+ oracleTxnPossiblyDirty: false,
+ isOracleManualTransaction: false,
+ });
+ app.use(pinia);
+ app.use(i18n);
+ app.mount(host);
+ await nextTick();
+
+ expect(host.textContent).not.toContain("toolbar.formatSql");
+
+ app.unmount();
+ host.remove();
+ });
+
it("mounts for a schema-aware connection whose watchEffect reads tier-gated selectors", async () => {
// Regression: the tier-gated showSchemaSelector is read eagerly by the
// schema-loading watchEffect, so the tier refs must be declared before any
diff --git a/apps/desktop/src/lib/__tests__/sql/sqlFormatter.spec.ts b/apps/desktop/src/lib/__tests__/sql/sqlFormatter.spec.ts
index e3901bdd41..c367d54f7c 100644
--- a/apps/desktop/src/lib/__tests__/sql/sqlFormatter.spec.ts
+++ b/apps/desktop/src/lib/__tests__/sql/sqlFormatter.spec.ts
@@ -11,7 +11,8 @@ describe("sqlFormatter", () => {
expect(sqlFormatterSource).not.toContain("(?<=");
});
- it("disables SQL formatting for VictoriaMetrics queries", () => {
+ it("disables SQL formatting for Redis and VictoriaMetrics queries", () => {
+ expect(canFormatSqlForDatabaseType("redis")).toBe(false);
expect(canFormatSqlForDatabaseType("victoriametrics")).toBe(false);
expect(canFormatSqlForDatabaseType("mysql")).toBe(true);
});
diff --git a/apps/desktop/src/lib/sql/sqlFormatter.ts b/apps/desktop/src/lib/sql/sqlFormatter.ts
index f66d4f2c21..8612a48baf 100644
--- a/apps/desktop/src/lib/sql/sqlFormatter.ts
+++ b/apps/desktop/src/lib/sql/sqlFormatter.ts
@@ -27,7 +27,7 @@ function resolveClickHouseIdentifierSafeDialect(sqlFormatter: SqlFormatterModule
}
export function canFormatSqlForDatabaseType(dbType: string | null | undefined): boolean {
- return dbType !== "victoriametrics";
+ return dbType !== "redis" && dbType !== "victoriametrics";
}
/**