feat(editor): merge multi-database query results into one view

This commit is contained in:
goodvecn-dev authored and GitHub committed 2026-09-23 10:36:40 +08:00
1 parent 9d07708617
commit 8b822e974b
31 files changed
+3085 -87

No files matched your search

@@ -8,6 +8,12 @@ export interface SqlExecutionDangerRequest {
connectionName?: string;
database?: string;
targetLabel?: string;
/**
* Every data source the pending batch will touch. Shown in the confirmation
* so the operator confirms the whole fan-out, not just the target that
* happened to reach the prompt first.
*/
targets?: string[];
databaseType?: DatabaseType;
/** Identifies a cancellable execution batch without coupling this store to its orchestrator. */
scopeId?: string;
@@ -18,13 +24,41 @@ interface QueuedDangerRequest {
resolve: (confirmed: boolean) => void;
}
/**
* A batch asks once per target, but the operator answers once per batch: the
* decision is remembered per `scopeId` so the remaining targets reuse it
* instead of re-prompting (and re-asking for the confirmation code).
*/
const MAX_REMEMBERED_SCOPES = 50;
export const useSqlExecutionDangerStore = defineStore("sqlExecutionDanger", () => {
const pending = ref<SqlExecutionDangerRequest>();
const queue: QueuedDangerRequest[] = [];
const scopeOutcome = new Map<string, boolean>();
let resolvePending: ((confirmed: boolean) => void) | undefined;
function rememberScopeOutcome(scopeId: string | undefined, confirmed: boolean): void {
if (!scopeId) return;
scopeOutcome.delete(scopeId);
scopeOutcome.set(scopeId, confirmed);
while (scopeOutcome.size > MAX_REMEMBERED_SCOPES) {
const oldest = scopeOutcome.keys().next().value;
if (oldest === undefined) break;
scopeOutcome.delete(oldest);
}
}
function rememberedOutcome(request: SqlExecutionDangerRequest): boolean | undefined {
return request.scopeId ? scopeOutcome.get(request.scopeId) : undefined;
}
function requestConfirmation(request: SqlExecutionDangerRequest): Promise<boolean> {
return new Promise<boolean>((resolve) => {
const remembered = rememberedOutcome(request);
if (remembered !== undefined) {
resolve(remembered);
return;
}
if (pending.value) {
queue.push({ request, resolve });
return;
@@ -38,13 +72,28 @@ export const useSqlExecutionDangerStore = defineStore("sqlExecutionDanger", () =
resolvePending = resolve;
}
/** Promotes queued requests, resolving the ones whose batch is already decided. */
function promoteNext(): void {
while (queue.length > 0) {
const next = queue.shift()!;
const remembered = rememberedOutcome(next.request);
if (remembered !== undefined) {
next.resolve(remembered);
continue;
}
begin(next.request, next.resolve);
return;
}
}
function settle(confirmed: boolean): void {
const request = pending.value;
const resolve = resolvePending;
resolvePending = undefined;
pending.value = undefined;
rememberScopeOutcome(request?.scopeId, confirmed);
resolve?.(confirmed);
const next = queue.shift();
if (next) begin(next.request, next.resolve);
promoteNext();
}
function confirm(): void {
@@ -72,6 +121,8 @@ export const useSqlExecutionDangerStore = defineStore("sqlExecutionDanger", () =
queue.splice(0, queue.length, ...retained);
cancelled.forEach((entry) => entry.resolve(false));
if (pending.value?.scopeId === scopeId) settle(false);
// A cancelled batch must prompt again if the same scope id is ever reused.
scopeOutcome.delete(scopeId);
}
return { pending, requestConfirmation, confirm, cancel, cancelAll, cancelScope };