mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-30 00:19:35 +00:00
feat: add execute_multi command and update query handling for multiple results
This commit is contained in:
+14
-1
@@ -1320,6 +1320,19 @@ async function setupFileDrop() {
|
||||
>
|
||||
{{ t('tabs.tableData') }}
|
||||
</Button>
|
||||
<template v-if="activeOutputView === 'result' && activeTab.results && activeTab.results.length > 1">
|
||||
<span class="mx-1 h-4 w-px bg-border" />
|
||||
<Button
|
||||
v-for="(_, rIdx) in activeTab.results"
|
||||
:key="rIdx"
|
||||
size="sm"
|
||||
:variant="activeTab.activeResultIndex === rIdx ? 'default' : 'ghost'"
|
||||
class="h-6 px-2 text-xs"
|
||||
@click="queryStore.setActiveResultIndex(activeTab.id, rIdx)"
|
||||
>
|
||||
{{ t('tabs.resultN', { n: rIdx + 1 }) }}
|
||||
</Button>
|
||||
</template>
|
||||
<Button
|
||||
size="sm"
|
||||
:variant="activeOutputView === 'explain' ? 'secondary' : 'ghost'"
|
||||
@@ -1343,7 +1356,7 @@ async function setupFileDrop() {
|
||||
/>
|
||||
|
||||
<template v-else>
|
||||
<DataGrid v-if="activeTab.result" :key="activeTab.id" class="flex-1 min-h-0" :result="activeTab.result" :sql="activeTab.lastExecutedSql || activeTab.sql" :loading="activeTab.isExecuting" />
|
||||
<DataGrid v-if="activeTab.result" :key="`${activeTab.id}-${activeTab.activeResultIndex ?? 0}`" class="flex-1 min-h-0" :result="activeTab.result" :sql="activeTab.lastExecutedSql || activeTab.sql" :loading="activeTab.isExecuting" />
|
||||
<div v-if="activeTab.result?.columns.includes('Error')" class="flex items-center gap-2 px-3 py-1.5 border-t bg-destructive/5">
|
||||
<Bot class="h-3.5 w-3.5 text-destructive" />
|
||||
<button class="text-xs text-destructive hover:underline" @click="fixWithAi(String(activeTab.result?.rows?.[0]?.[0] ?? ''))">
|
||||
|
||||
@@ -94,6 +94,7 @@ export default {
|
||||
tooltipDatabase: "Database:",
|
||||
tooltipTable: "Table:",
|
||||
tooltipCollection: "Collection:",
|
||||
resultN: "Result {n}",
|
||||
},
|
||||
grid: {
|
||||
rows: "{count} rows",
|
||||
|
||||
@@ -96,6 +96,7 @@ export default {
|
||||
tooltipDatabase: "数据库:",
|
||||
tooltipTable: "表:",
|
||||
tooltipCollection: "集合:",
|
||||
resultN: "结果 {n}",
|
||||
},
|
||||
grid: {
|
||||
rows: "{count} 行",
|
||||
|
||||
@@ -138,6 +138,10 @@ export async function executeQuery(connectionId: string, database: string, sql:
|
||||
return invoke("execute_query", { connectionId, database, sql, executionId });
|
||||
}
|
||||
|
||||
export async function executeMulti(connectionId: string, database: string, sql: string, executionId?: string): Promise<QueryResult[]> {
|
||||
return invoke("execute_multi", { connectionId, database, sql, executionId });
|
||||
}
|
||||
|
||||
export async function cancelQuery(executionId: string): Promise<boolean> {
|
||||
return invoke("cancel_query", { executionId });
|
||||
}
|
||||
|
||||
@@ -174,11 +174,25 @@ export const useQueryStore = defineStore("query", () => {
|
||||
tab.executionId = executionId;
|
||||
tab.lastExecutedSql = sql;
|
||||
try {
|
||||
tab.result = await api.executeQuery(tab.connectionId, tab.database, sql, executionId);
|
||||
const results = await api.executeMulti(tab.connectionId, tab.database, sql, executionId);
|
||||
const current = tabs.value.find((t) => t.id === id);
|
||||
if (current?.executionId === executionId) {
|
||||
if (results.length > 1) {
|
||||
current.results = results;
|
||||
current.activeResultIndex = 0;
|
||||
current.result = results[0];
|
||||
} else {
|
||||
current.results = undefined;
|
||||
current.activeResultIndex = undefined;
|
||||
current.result = results[0];
|
||||
}
|
||||
}
|
||||
} catch (e: any) {
|
||||
const current = tabs.value.find((t) => t.id === id);
|
||||
if (current?.executionId === executionId) {
|
||||
current.result = toErrorResult(e);
|
||||
current.results = undefined;
|
||||
current.activeResultIndex = undefined;
|
||||
}
|
||||
} finally {
|
||||
const current = tabs.value.find((t) => t.id === id);
|
||||
@@ -277,6 +291,13 @@ export const useQueryStore = defineStore("query", () => {
|
||||
}
|
||||
}
|
||||
|
||||
function setActiveResultIndex(id: string, index: number) {
|
||||
const tab = tabs.value.find((t) => t.id === id);
|
||||
if (!tab?.results || index < 0 || index >= tab.results.length) return;
|
||||
tab.activeResultIndex = index;
|
||||
tab.result = tab.results[index];
|
||||
}
|
||||
|
||||
function trimResultCache() {
|
||||
const inactive = tabs.value.filter((t) => t.id !== activeTabId.value && t.result);
|
||||
if (inactive.length > MAX_CACHED_RESULTS) {
|
||||
@@ -299,6 +320,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
setTableMeta,
|
||||
setExecuting,
|
||||
setErrorResult,
|
||||
setActiveResultIndex,
|
||||
executeCurrentTab,
|
||||
executeCurrentSql,
|
||||
executeTabSql,
|
||||
|
||||
@@ -110,6 +110,8 @@ export interface QueryTab {
|
||||
lastExecutedSql?: string;
|
||||
pinned?: boolean;
|
||||
result?: QueryResult;
|
||||
results?: QueryResult[];
|
||||
activeResultIndex?: number;
|
||||
explainPlan?: import("@/lib/explainPlan").ParsedExplainPlan;
|
||||
explainError?: string;
|
||||
explainSql?: string;
|
||||
|
||||
Reference in New Issue
Block a user