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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
feat: support schema-qualified table completion in SQL editor
t8y248785162e3a7
diff --git a/src/components/editor/QueryEditor.vue b/src/components/editor/QueryEditor.vueindex 359f57bfdf..0d55651a7f 100644--- a/src/components/editor/QueryEditor.vue+++ b/src/components/editor/QueryEditor.vue@@ -128,7 +128,7 @@ async function provideSqlCompletions(currentState: import("@codemirror/state").Econst fullDoc = currentState.doc.toString();const completionContext = getSqlCompletionContext(fullDoc, position);const shouldLoadTables = completionContext.suggestTables || !!completionContext.qualifier;- const tables = shouldLoadTables+ let tables = shouldLoadTables? await connectionStore.listCompletionTables(props.connectionId,props.database,@@ -137,6 +137,22 @@ async function provideSqlCompletions(currentState: import("@codemirror/state").E): cachedTables;+ // If qualifier didn't match any table names, try it as a schema name+ let qualifierIsSchema = false;+ if (completionContext.qualifier && completionContext.suggestTables && tables.length === 0) {+ const schemaTables = await connectionStore.listCompletionTables(+ props.connectionId,+ props.database,+ completionContext.prefix,+ MAX_COMPLETION_TABLES,+ completionContext.qualifier,+ );+ if (schemaTables.length > 0) {+ tables = schemaTables;+ qualifierIsSchema = true;+ }+ }+// Collect referenced tables — enrich with schema from filtered table lookuplet refs = completionContext.referencedTables.map((rt) => {// If no schema, look it up in the cached tables@@ -200,7 +216,11 @@ async function provideSqlCompletions(currentState: import("@codemirror/state").E}}- const items = buildSqlCompletionItemsFromContext(completionContext, {+ const effectiveContext = qualifierIsSchema+ ? { ...completionContext, qualifier: undefined, suggestTables: true, suggestColumns: false }+ : completionContext;++ const items = buildSqlCompletionItemsFromContext(effectiveContext, {tables,columnsByTable,});diff --git a/src/stores/connectionStore.ts b/src/stores/connectionStore.tsindex d4163d0461..e86deb7b1c 100644--- a/src/stores/connectionStore.ts+++ b/src/stores/connectionStore.ts@@ -995,9 +995,10 @@ export const useConnectionStore = defineStore("connection", () => {database: string,filter = "",limit?: number,+ schema?: string,): Promise<SqlCompletionTable[]> {const normalizedFilter = filter.trim().toLowerCase();- const cacheKey = `${connectionId}:${database}:${normalizedFilter}:${limit ?? ""}`;+ const cacheKey = `${connectionId}:${database}:${normalizedFilter}:${limit ?? ""}:${schema ?? ""}`;if (completionTablesCache.value[cacheKey]) {return completionTablesCache.value[cacheKey];}@@ -1005,7 +1006,7 @@ export const useConnectionStore = defineStore("connection", () => {await ensureConnected(connectionId);if (isSchemaAwareDatabase(connectionId)) {- const schemas = await api.listSchemas(connectionId, database);+ const schemas = schema ? [schema] : await api.listSchemas(connectionId, database);if (normalizedFilter || limit) {const limitedTables: SqlCompletionTable[] = [];for (const schema of schemas) {