mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-23 02:40:11 +00:00
fix: sync saved sql file connection on tab connection change
This commit is contained in:
@@ -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"]>) {
|
||||
|
||||
@@ -196,6 +196,7 @@ export const useSavedSqlStore = defineStore("savedSql", () => {
|
||||
database: input.database,
|
||||
schema: input.schema,
|
||||
sql: input.sql,
|
||||
connectionId: input.connectionId,
|
||||
updatedAt: timestamp,
|
||||
}
|
||||
: {
|
||||
|
||||
Reference in New Issue
Block a user