feat(query): 优化多条查询语句结果展示与语句匹配问题 (#2697)
This commit is contained in:
5 files changed
+172
-44
No files matched your search
@@ -3,6 +3,7 @@ import { test } from "vitest";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { isReactive } from "vue";
|
||||
import { decodeQueryResultArchive } from "../../apps/desktop/src/lib/query/queryResultArchive.ts";
|
||||
import { resultSqlForGrid } from "../../apps/desktop/src/lib/tabs/tabPresentation.ts";
|
||||
import { useConnectionStore } from "../../apps/desktop/src/stores/connectionStore.ts";
|
||||
import { useQueryStore } from "../../apps/desktop/src/stores/queryStore.ts";
|
||||
import { useSettingsStore } from "../../apps/desktop/src/stores/settingsStore.ts";
|
||||
@@ -2487,6 +2488,101 @@ test("mongo multi-command execution runs writes sequentially and keeps grouped r
|
||||
assert.equal(tab?.results?.length, 2);
|
||||
assert.equal(tab?.activeResultIndex, 0);
|
||||
assert.equal(tab?.result?.affected_rows, 1);
|
||||
assert.deepEqual(
|
||||
tab?.results?.map((result) => result.sourceStatement),
|
||||
['db.users.insertOne({ name: "Ada" })', 'db.users.insertOne({ name: "Grace" })'],
|
||||
);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
restoreStorage();
|
||||
}
|
||||
});
|
||||
|
||||
test("redis multi-command execution records source statements for each result", async () => {
|
||||
const restoreStorage = installMemoryStorage();
|
||||
setActivePinia(createPinia());
|
||||
const connectionStore = useConnectionStore();
|
||||
const store = useQueryStore();
|
||||
const originalFetch = globalThis.fetch;
|
||||
const commandBodies: any[] = [];
|
||||
|
||||
connectionStore.addEphemeralConnection({
|
||||
...conn("redis-1"),
|
||||
db_type: "redis",
|
||||
port: 6379,
|
||||
});
|
||||
|
||||
globalThis.fetch = withConnectionHealthMock(async (input, init) => {
|
||||
const url = String(input);
|
||||
if (url === "/api/redis/execute-command") {
|
||||
const body = JSON.parse(String(init?.body ?? "{}"));
|
||||
commandBodies.push(body);
|
||||
if (body.command === "BAD") return new Response("bad command", { status: 500 });
|
||||
return new Response(JSON.stringify({ command: body.command, safety: "allowed", value: body.command === "GET user:1" ? "Ada" : "OK" }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
return new Response("unexpected request", { status: 500 });
|
||||
});
|
||||
|
||||
try {
|
||||
const tabId = store.createTab("redis-1", "0", "Redis", "query", "");
|
||||
await store.executeTabSql(tabId, "GET user:1\nBAD\nPING");
|
||||
const tab = store.tabs.find((item) => item.id === tabId);
|
||||
|
||||
assert.deepEqual(
|
||||
commandBodies.map((body) => body.command),
|
||||
["GET user:1", "BAD", "PING"],
|
||||
);
|
||||
assert.deepEqual(
|
||||
tab?.results?.map((result) => result.sourceStatement),
|
||||
["GET user:1", "BAD", "PING"],
|
||||
);
|
||||
assert.deepEqual(tab?.results?.[1]?.columns, ["Error"]);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
restoreStorage();
|
||||
}
|
||||
});
|
||||
|
||||
test("mongo multi-command execution records source statements for error results", async () => {
|
||||
const restoreStorage = installMemoryStorage();
|
||||
setActivePinia(createPinia());
|
||||
const connectionStore = useConnectionStore();
|
||||
const store = useQueryStore();
|
||||
const originalFetch = globalThis.fetch;
|
||||
let insertCount = 0;
|
||||
|
||||
connectionStore.addEphemeralConnection({
|
||||
...conn("mongo-1"),
|
||||
db_type: "mongodb",
|
||||
port: 27017,
|
||||
});
|
||||
|
||||
globalThis.fetch = withConnectionHealthMock(async (input) => {
|
||||
const url = String(input);
|
||||
if (url === "/api/mongo/insert-documents") {
|
||||
insertCount += 1;
|
||||
if (insertCount === 2) return new Response("duplicate key", { status: 500 });
|
||||
return new Response(JSON.stringify({ affected_rows: 1 }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
}
|
||||
return new Response("unexpected request", { status: 500 });
|
||||
});
|
||||
|
||||
try {
|
||||
const tabId = store.createTab("mongo-1", "accounting", "Query", "query", "");
|
||||
await store.executeTabSql(tabId, 'db.users.insertOne({ name: "Ada" });\ndb.users.insertOne({ name: "Ada" });');
|
||||
const tab = store.tabs.find((item) => item.id === tabId);
|
||||
|
||||
assert.deepEqual(
|
||||
tab?.results?.map((result) => result.sourceStatement),
|
||||
['db.users.insertOne({ name: "Ada" })', 'db.users.insertOne({ name: "Ada" })'],
|
||||
);
|
||||
assert.deepEqual(tab?.results?.[1]?.columns, ["Error"]);
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
restoreStorage();
|
||||
@@ -3453,6 +3549,10 @@ test("query results keep readable table source labels with active database conte
|
||||
tab?.results?.map((result) => result.sourceStatement),
|
||||
["select * from users", "select * from orders"],
|
||||
);
|
||||
assert.equal(resultSqlForGrid(tab!), "select * from users");
|
||||
store.setActiveResultIndex(tabId, 1);
|
||||
tab = store.tabs.find((item) => item.id === tabId);
|
||||
assert.equal(resultSqlForGrid(tab!), "select * from orders");
|
||||
|
||||
await store.executeTabSql(defaultDatabaseTabId, "SELECT *\nFROM apis AS ap\nLIMIT 10;\n\nSELECT *\nFROM menus AS mn\nLIMIT 10;");
|
||||
tab = store.tabs.find((item) => item.id === defaultDatabaseTabId);
|
||||
@@ -3473,6 +3573,7 @@ test("query results keep readable table source labels with active database conte
|
||||
await store.executeTabSql(tabId, "update users set active = true; select * from users");
|
||||
tab = store.tabs.find((item) => item.id === tabId);
|
||||
assert.equal(tab?.results?.[0]?.sourceLabel, undefined);
|
||||
assert.equal(tab?.results?.[0]?.sourceStatement, "update users set active = true");
|
||||
assert.equal(tab?.results?.[1]?.sourceLabel, "db.users");
|
||||
assert.equal(tab?.results?.[1]?.sourceStatement, "select * from users");
|
||||
} finally {
|
||||
|
||||
Reference in new issue
Block a user