fix: sync saved sql file connection on tab connection change

This commit is contained in:
t8y2
2026-06-21 23:49:54 +08:00
parent c9cd80fc79
commit 2fc835060e
2 changed files with 18 additions and 0 deletions
+17
View File
@@ -38,6 +38,7 @@ import { decodeQueryResultArchive, encodeQueryResultArchive, type DecodedQueryRe
import * as api from "@/lib/api";
import { useConnectionStore } from "@/stores/connectionStore";
import { useSettingsStore } from "@/stores/settingsStore";
import { useSavedSqlStore } from "@/stores/savedSqlStore";
import type { SavedSqlFile } from "@/types/database";
const STORAGE_KEY = "dbx-open-tabs";
@@ -942,6 +943,22 @@ export const useQueryStore = defineStore("query", () => {
tab.resultSortedSql = undefined;
clearExplain(tab);
tab.tableMeta = undefined;
// Sync connection change back to the saved SQL file if this tab is linked
if (tab.savedSqlId) {
const savedSqlStore = useSavedSqlStore();
const existing = savedSqlStore.getFile(tab.savedSqlId);
if (existing) {
void savedSqlStore.saveFile({
id: existing.id,
connectionId,
name: existing.name,
database,
schema: existing.schema,
sql: existing.sql,
});
}
}
}
function setTableMeta(id: string, meta: NonNullable<QueryTab["tableMeta"]>) {
+1
View File
@@ -196,6 +196,7 @@ export const useSavedSqlStore = defineStore("savedSql", () => {
database: input.database,
schema: input.schema,
sql: input.sql,
connectionId: input.connectionId,
updatedAt: timestamp,
}
: {