feat(editor): retain multiple query result runs
This commit is contained in:
1 parent
fddc0fdf50
commit
7f20b03177
26 files changed
+846
-109
No files matched your search
+138
-3
@@ -147,6 +147,81 @@ describe("useSqlExecution", () => {
|
||||
expect(executeCurrentSql).toHaveBeenCalledWith(selectedSql, { sourceOffset: selectionFrom });
|
||||
});
|
||||
|
||||
it("forwards execute-in-new-result-tab intent to the query store", async () => {
|
||||
const sql = "SELECT * FROM users";
|
||||
const activeTab = ref<QueryTab | undefined>({ ...queryTab("app"), sql });
|
||||
const activeConnection = ref<ConnectionConfig | undefined>(connection("mysql"));
|
||||
const activeOutputView = ref<"result" | "summary" | "explain" | "chart">("result");
|
||||
const queryStore = useQueryStore();
|
||||
const executeCurrentSql = vi.spyOn(queryStore, "executeCurrentSql").mockImplementation(async () => {
|
||||
if (activeTab.value) activeTab.value.result = { columns: ["id"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 };
|
||||
});
|
||||
vi.spyOn(useHistoryStore(), "add").mockResolvedValue(undefined);
|
||||
|
||||
const execution = useSqlExecution({
|
||||
activeTab: computed(() => activeTab.value),
|
||||
activeConnection: computed(() => activeConnection.value),
|
||||
executableSql: computed(() => sql),
|
||||
activeOutputView,
|
||||
});
|
||||
|
||||
await execution.tryExecuteInNewResultTab();
|
||||
|
||||
expect(executeCurrentSql).toHaveBeenCalledWith(sql, { openInNewResultTab: true });
|
||||
});
|
||||
|
||||
it("does not record or refresh when a new-result execution restores the prior run", async () => {
|
||||
const result = { columns: ["value"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 };
|
||||
const activeTab = ref<QueryTab | undefined>({ ...queryTab("app"), result });
|
||||
const activeConnection = ref<ConnectionConfig | undefined>(connection("mysql"));
|
||||
const activeOutputView = ref<"result" | "summary" | "explain" | "chart">("result");
|
||||
const queryStore = useQueryStore();
|
||||
vi.spyOn(queryStore, "executeCurrentSql").mockResolvedValue(false);
|
||||
const addHistory = vi.spyOn(useHistoryStore(), "add").mockResolvedValue(undefined);
|
||||
const refreshObjects = vi.spyOn(useConnectionStore(), "refreshObjectListTreeNode").mockResolvedValue(undefined);
|
||||
|
||||
const execution = useSqlExecution({
|
||||
activeTab: computed(() => activeTab.value),
|
||||
activeConnection: computed(() => activeConnection.value),
|
||||
executableSql: computed(() => "CREATE TABLE users (id INT)"),
|
||||
activeOutputView,
|
||||
});
|
||||
|
||||
await execution.tryExecuteInNewResultTab();
|
||||
|
||||
expect(addHistory).not.toHaveBeenCalled();
|
||||
expect(refreshObjects).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("keeps the new-result-tab intent through SQL parameter input", async () => {
|
||||
const sql = "SELECT * FROM users WHERE id = :id";
|
||||
const resolvedSql = "SELECT * FROM users WHERE id = 7";
|
||||
const activeTab = ref<QueryTab | undefined>({ ...queryTab("app"), sql });
|
||||
const activeConnection = ref<ConnectionConfig | undefined>(connection("mysql"));
|
||||
const activeOutputView = ref<"result" | "summary" | "explain" | "chart">("result");
|
||||
const queryStore = useQueryStore();
|
||||
const executeCurrentSql = vi.spyOn(queryStore, "executeCurrentSql").mockImplementation(async () => {
|
||||
if (activeTab.value) activeTab.value.result = { columns: ["id"], rows: [[7]], affected_rows: 0, execution_time_ms: 1 };
|
||||
});
|
||||
vi.spyOn(useHistoryStore(), "add").mockResolvedValue(undefined);
|
||||
|
||||
const execution = useSqlExecution({
|
||||
activeTab: computed(() => activeTab.value),
|
||||
activeConnection: computed(() => activeConnection.value),
|
||||
executableSql: computed(() => sql),
|
||||
activeOutputView,
|
||||
});
|
||||
|
||||
await execution.tryExecuteInNewResultTab();
|
||||
|
||||
expect(execution.showSqlParameterDialog.value).toBe(true);
|
||||
expect(executeCurrentSql).not.toHaveBeenCalled();
|
||||
|
||||
await execution.onSqlParametersConfirm(resolvedSql);
|
||||
|
||||
expect(executeCurrentSql).toHaveBeenCalledWith(resolvedSql, { openInNewResultTab: true });
|
||||
});
|
||||
|
||||
it("sends native SET variables without client-side expansion", async () => {
|
||||
const activeTab = ref<QueryTab | undefined>(queryTab("app"));
|
||||
const activeConnection = ref<ConnectionConfig | undefined>(connection("mysql"));
|
||||
@@ -325,7 +400,7 @@ describe("useSqlExecution", () => {
|
||||
expect(addHistory).toHaveBeenCalledWith(expect.objectContaining({ success: false, error: "relation does not exist" }));
|
||||
});
|
||||
|
||||
it("keeps the full dangerous script pending and executes it unchanged after confirmation", async () => {
|
||||
it("keeps the full dangerous script and new-result-tab intent through confirmation", async () => {
|
||||
const activeTab = ref<QueryTab | undefined>(queryTab("app"));
|
||||
const activeConnection = ref<ConnectionConfig | undefined>(connection("mysql"));
|
||||
const activeOutputView = ref<"result" | "summary" | "explain" | "chart">("result");
|
||||
@@ -343,7 +418,7 @@ describe("useSqlExecution", () => {
|
||||
activeOutputView,
|
||||
});
|
||||
|
||||
await execution.tryExecute();
|
||||
await execution.tryExecuteInNewResultTab();
|
||||
|
||||
expect(execution.showDangerDialog.value).toBe(true);
|
||||
expect(execution.pendingDangerSql.value).toBe(sql);
|
||||
@@ -351,7 +426,67 @@ describe("useSqlExecution", () => {
|
||||
|
||||
await execution.onDangerConfirm();
|
||||
|
||||
expect(executeCurrentSql).toHaveBeenCalledWith(sql, {});
|
||||
expect(executeCurrentSql).toHaveBeenCalledWith(sql, { openInNewResultTab: true });
|
||||
});
|
||||
|
||||
it("keeps the active retained result when a new-result dangerous prompt is cancelled", async () => {
|
||||
const result = { columns: ["value"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 };
|
||||
const activeTab = ref<QueryTab | undefined>({
|
||||
...queryTab("app"),
|
||||
result,
|
||||
resultRuns: [{ id: "run-1", title: "Run 1", sequence: 1, sql: "SELECT 1", createdAt: 1, result }],
|
||||
activeResultRunId: "run-1",
|
||||
});
|
||||
const activeConnection = ref<ConnectionConfig | undefined>(connection("mysql"));
|
||||
const activeOutputView = ref<"result" | "summary" | "explain" | "chart">("result");
|
||||
const queryStore = useQueryStore();
|
||||
const executeCurrentSql = vi.spyOn(queryStore, "executeCurrentSql");
|
||||
|
||||
const execution = useSqlExecution({
|
||||
activeTab: computed(() => activeTab.value),
|
||||
activeConnection: computed(() => activeConnection.value),
|
||||
executableSql: computed(() => "DROP TABLE users"),
|
||||
activeOutputView,
|
||||
});
|
||||
|
||||
await execution.tryExecuteInNewResultTab();
|
||||
expect(execution.showDangerDialog.value).toBe(true);
|
||||
|
||||
execution.showDangerDialog.value = false;
|
||||
await Promise.resolve();
|
||||
|
||||
expect(executeCurrentSql).not.toHaveBeenCalled();
|
||||
expect(activeTab.value?.activeResultRunId).toBe("run-1");
|
||||
expect(activeTab.value?.result).toEqual(result);
|
||||
});
|
||||
|
||||
it("keeps the new-result-tab intent through Redis command confirmation", async () => {
|
||||
const sql = "DEL user:1";
|
||||
const activeTab = ref<QueryTab | undefined>({ ...queryTab("0"), sql });
|
||||
const activeConnection = ref<ConnectionConfig | undefined>(connection("redis"));
|
||||
const activeOutputView = ref<"result" | "summary" | "explain" | "chart">("result");
|
||||
const queryStore = useQueryStore();
|
||||
const executeCurrentSql = vi.spyOn(queryStore, "executeCurrentSql").mockImplementation(async () => {
|
||||
if (activeTab.value) activeTab.value.result = { columns: [], rows: [], affected_rows: 1, execution_time_ms: 1 };
|
||||
});
|
||||
vi.spyOn(useHistoryStore(), "add").mockResolvedValue(undefined);
|
||||
|
||||
const execution = useSqlExecution({
|
||||
activeTab: computed(() => activeTab.value),
|
||||
activeConnection: computed(() => activeConnection.value),
|
||||
executableSql: computed(() => sql),
|
||||
activeOutputView,
|
||||
blockDangerousRedisCommands: ref(true),
|
||||
});
|
||||
|
||||
await execution.tryExecuteInNewResultTab();
|
||||
|
||||
expect(execution.showDangerDialog.value).toBe(true);
|
||||
expect(executeCurrentSql).not.toHaveBeenCalled();
|
||||
|
||||
await execution.onDangerConfirm();
|
||||
|
||||
expect(executeCurrentSql).toHaveBeenCalledWith(sql, { skipRedisSafetyCheck: false, openInNewResultTab: true });
|
||||
});
|
||||
|
||||
it("requires production confirmation even when ordinary danger prompts are disabled", async () => {
|
||||
|
||||
Reference in new issue
Block a user