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(query): reload connection config before execute

t8y230a48a878cc1
diff --git a/apps/desktop/src/stores/connectionStore.ts b/apps/desktop/src/stores/connectionStore.ts
index 04d5fdf46f..6f2a1494eb 100644
--- a/apps/desktop/src/stores/connectionStore.ts
+++ b/apps/desktop/src/stores/connectionStore.ts
@@ -128,6 +128,7 @@ export const useConnectionStore = defineStore("connection", () => {
let layoutPersistTimer: ReturnType<typeof setTimeout> | null = null;
const staleTreeRefreshIds = new Set<string>();
let beforeConnectHandler: BeforeConnectHandler | null = null;
+ let initFromDiskPromise: Promise<void> | null = null;
function startEditing(id: string) {
editingConnectionId.value = id;
@@ -660,7 +661,11 @@ export const useConnectionStore = defineStore("connection", () => {
async function ensureConnected(connectionId: string) {
if (connectedIds.value.has(connectionId)) return;
- const config = getConfig(connectionId);
+ let config = getConfig(connectionId);
+ if (!config) {
+ await initFromDisk();
+ config = getConfig(connectionId);
+ }
if (!config) {
const error = new Error("Connection config not found");
recordConnectionError(connectionId, error);
@@ -1737,15 +1742,22 @@ export const useConnectionStore = defineStore("connection", () => {
}
async function initFromDisk() {
- pinnedTreeNodeIds.value = await loadPinnedTreeNodeIds();
- const saved = await api.loadConnections();
- connections.value = saved.map(normalizeConnection);
- const savedLayout = await api.loadSidebarLayout();
- sidebarLayout.value = reconcileLayout(
- connections.value.map((c) => c.id),
- savedLayout,
- );
- rebuildTreeNodes();
+ if (!initFromDiskPromise) {
+ initFromDiskPromise = (async () => {
+ pinnedTreeNodeIds.value = await loadPinnedTreeNodeIds();
+ const saved = await api.loadConnections();
+ connections.value = saved.map(normalizeConnection);
+ const savedLayout = await api.loadSidebarLayout();
+ sidebarLayout.value = reconcileLayout(
+ connections.value.map((c) => c.id),
+ savedLayout,
+ );
+ rebuildTreeNodes();
+ })().finally(() => {
+ initFromDiskPromise = null;
+ });
+ }
+ await initFromDiskPromise;
}
function addEphemeralConnection(config: ConnectionConfig) {
diff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.ts
index 1f327e7435..35c9c0f14a 100644
--- a/apps/desktop/src/stores/queryStore.ts
+++ b/apps/desktop/src/stores/queryStore.ts
@@ -558,6 +558,7 @@ export const useQueryStore = defineStore("query", () => {
let useAgentResultSession = false;
try {
const connStore = useConnectionStore();
+ await connStore.ensureConnected(tab.connectionId);
const conn = connStore.getConfig(tab.connectionId);
const useAgentCursor = !!conn?.db_type && AGENT_DRIVER_TYPES.has(conn.db_type);
const queryTimeoutSecs =
diff --git a/packages/app-tests/queryStore.test.ts b/packages/app-tests/queryStore.test.ts
index 31a97fb00c..5294f88d5a 100644
--- a/packages/app-tests/queryStore.test.ts
+++ b/packages/app-tests/queryStore.test.ts
@@ -1,7 +1,9 @@
import { strict as assert } from "node:assert";
import test from "node:test";
import { createPinia, setActivePinia } from "pinia";
+import { useConnectionStore } from "../../apps/desktop/src/stores/connectionStore.ts";
import { useQueryStore } from "../../apps/desktop/src/stores/queryStore.ts";
+import type { ConnectionConfig } from "../../apps/desktop/src/types/database.ts";
import type { QueryResult } from "../../apps/desktop/src/types/database.ts";
function installMemoryStorage() {
@@ -22,6 +24,18 @@ function installMemoryStorage() {
};
}
+function conn(id: string): ConnectionConfig {
+ return {
+ id,
+ name: id,
+ db_type: "postgres",
+ host: "localhost",
+ port: 5432,
+ username: "postgres",
+ password: "",
+ };
+}
+
test("setErrorResult stops loading and shows the error result", () => {
setActivePinia(createPinia());
const store = useQueryStore();
@@ -41,11 +55,14 @@ test("setErrorResult stops loading and shows the error result", () => {
test("evicting cached tab results releases multi-result payloads and sessions", async () => {
const restoreStorage = installMemoryStorage();
setActivePinia(createPinia());
+ const connectionStore = useConnectionStore();
const store = useQueryStore();
const originalFetch = globalThis.fetch;
let executeCount = 0;
const closedSessions: string[] = [];
+ connectionStore.addEphemeralConnection(conn("conn-1"));
+
globalThis.fetch = (async (input, init) => {
const url = String(input);
if (url === "/api/query/execute-multi") {