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(sql): add databaseType parameter to findStatementAtCursor function

t8y2872569265d79
diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue
index 7d8925c639..fee10312b6 100644
--- a/apps/desktop/src/App.vue
+++ b/apps/desktop/src/App.vue
@@ -173,6 +173,7 @@ async function resolveActiveExecutableSql() {
? await resolveExecutableSqlWithBackend(tab.sql, selectedSql.value, {
mode: settingsStore.editorSettings.executeMode,
cursorPos: cursorPos.value,
+ databaseType: activeConnection.value?.db_type,
})
: "";
}
diff --git a/apps/desktop/src/lib/http.ts b/apps/desktop/src/lib/http.ts
index 5bce01dd66..b7c83a7633 100644
--- a/apps/desktop/src/lib/http.ts
+++ b/apps/desktop/src/lib/http.ts
@@ -462,8 +462,12 @@ export async function analyzeSqlReferences(sql: string, dialect?: string): Promi
return post("/api/query/analyze-sql-references", { sql, dialect });
}
-export async function findStatementAtCursor(sql: string, cursorPos: number): Promise<string> {
- return post("/api/query/find-statement-at-cursor", { sql, cursorPos });
+export async function findStatementAtCursor(
+ sql: string,
+ cursorPos: number,
+ databaseType?: DatabaseType,
+): Promise<string> {
+ return post("/api/query/find-statement-at-cursor", { sql, cursorPos, databaseType });
}
export async function prepareQueryPaginationExecutionPlan(
diff --git a/apps/desktop/src/lib/sqlExecutionTarget.ts b/apps/desktop/src/lib/sqlExecutionTarget.ts
index d687dbc283..2e5e861258 100644
--- a/apps/desktop/src/lib/sqlExecutionTarget.ts
+++ b/apps/desktop/src/lib/sqlExecutionTarget.ts
@@ -1,4 +1,5 @@
import * as api from "./api";
+import type { DatabaseType } from "@/types/database";
export type ExecuteMode = "all" | "current";
@@ -20,13 +21,13 @@ export function resolveExecutableSql(
export async function resolveExecutableSqlWithBackend(
fullSql: string,
selectedSql: string,
- options?: { mode?: ExecuteMode; cursorPos?: number },
+ options?: { mode?: ExecuteMode; cursorPos?: number; databaseType?: DatabaseType },
): Promise<string> {
const trimmedSelection = selectedSql.trim();
if (trimmedSelection) return trimmedSelection;
if (options?.mode === "current" && options.cursorPos !== undefined) {
- return await api.findStatementAtCursor(fullSql, options.cursorPos);
+ return await api.findStatementAtCursor(fullSql, options.cursorPos, options.databaseType);
}
return fullSql;
diff --git a/apps/desktop/src/lib/tauri.ts b/apps/desktop/src/lib/tauri.ts
index a4a3746eda..2c627d7441 100644
--- a/apps/desktop/src/lib/tauri.ts
+++ b/apps/desktop/src/lib/tauri.ts
@@ -416,8 +416,12 @@ export async function analyzeSqlReferences(sql: string, dialect?: string): Promi
return invoke("analyze_sql_references", { sql, dialect });
}
-export async function findStatementAtCursor(sql: string, cursorPos: number): Promise<string> {
- return invoke("find_statement_at_cursor", { sql, cursorPos });
+export async function findStatementAtCursor(
+ sql: string,
+ cursorPos: number,
+ databaseType?: DatabaseType,
+): Promise<string> {
+ return invoke("find_statement_at_cursor", { sql, cursorPos, databaseType });
}
export async function prepareQueryPaginationExecutionPlan(
diff --git a/packages/app-tests/sqlStatementBackend.test.ts b/packages/app-tests/sqlStatementBackend.test.ts
index 4fcd18b3df..a9cfe0c04a 100644
--- a/packages/app-tests/sqlStatementBackend.test.ts
+++ b/packages/app-tests/sqlStatementBackend.test.ts
@@ -19,7 +19,7 @@ test("shared API exposes backend current statement resolution", () => {
});
test("execution target prefers backend current statement resolution", () => {
- assert.match(executionTargetSource, /api\.findStatementAtCursor\(fullSql, options\.cursorPos\)/);
+ assert.match(executionTargetSource, /api\.findStatementAtCursor\(fullSql, options\.cursorPos, options\.databaseType\)/);
assert.doesNotMatch(executionTargetSource, /sqlStatementSplit/);
assert.doesNotMatch(executionTargetSource, /return findStatementAtCursor\(fullSql, options\.cursorPos\)/);
});