feat: show username/password fields for Access database connections

This commit is contained in:
t8y2 committed 2026-06-10 08:37:18 +08:00
1 parent 2e021d37d1
commit edba8214b5
477 files changed
+5720 -19773

No files matched your search

+44 -262
View File
@@ -7,12 +7,7 @@ import { orderPinnedFirst } from "@/lib/pinnedItems";
import { canCancelQueryExecution } from "@/lib/queryExecutionState";
import { closeAllTabsState, closeOtherTabsState } from "@/lib/tabCloseActions";
import { buildExplainSql, parseExplainResult, parseDamengExplainText } from "@/lib/explainPlan";
import {
allEditableColumnsWriteable,
allPrimaryKeysPresent,
sourceColumnsForResult,
type EditableQueryInfo,
} from "@/lib/sqlAnalysis";
import { allEditableColumnsWriteable, allPrimaryKeysPresent, sourceColumnsForResult, type EditableQueryInfo } from "@/lib/sqlAnalysis";
import { restoreOpenTabsState, serializeOpenTabs } from "@/lib/openTabsPersistence";
import {
evaluateMongoAggregateSafety,
@@ -32,20 +27,10 @@ import { editablePrimaryKeys } from "@/lib/tableEditing";
import { TABLE_DATA_EXPORT_PAGE_SIZE } from "@/lib/tableDataExport";
import { tableMetaForDataTab } from "@/lib/tableDataTabMeta";
import { quoteTableIdentifier } from "@/lib/tableSelectSql";
import {
connectionUsesDatabaseObjectTreeMode,
connectionUsesSchemaExecutionContext,
effectiveDatabaseTypeForConnection,
} from "@/lib/jdbcDialect";
import { connectionUsesDatabaseObjectTreeMode, connectionUsesSchemaExecutionContext, effectiveDatabaseTypeForConnection } from "@/lib/jdbcDialect";
import { queryTimeoutSecsForConnection } from "@/lib/queryTimeout";
import { clearDataGridPendingSnapshotsForTab } from "@/composables/useDataGridEditor";
import {
buildTabResultSnapshot,
deleteTabResultSnapshot,
readTabResultSnapshot,
tabResultCacheKey,
writeTabResultSnapshot,
} from "@/lib/tabResultCache";
import { buildTabResultSnapshot, deleteTabResultSnapshot, readTabResultSnapshot, tabResultCacheKey, writeTabResultSnapshot } from "@/lib/tabResultCache";
import * as api from "@/lib/api";
import { useConnectionStore } from "@/stores/connectionStore";
import { useSettingsStore } from "@/stores/settingsStore";
@@ -86,12 +71,7 @@ function normalizeOracleLikeMetadataIdentifier(dbType: string, identifier: strin
return identifier.toUpperCase();
}
function normalizeOracleLikeQueryAnalysis(
dbType: string,
analysis: EditableQueryInfo,
schema: string | undefined,
tableName: string,
): EditableQueryInfo {
function normalizeOracleLikeQueryAnalysis(dbType: string, analysis: EditableQueryInfo, schema: string | undefined, tableName: string): EditableQueryInfo {
if (!ORACLE_LIKE_METADATA_TYPES.has(dbType)) return analysis;
return {
...analysis,
@@ -137,21 +117,11 @@ export const useQueryStore = defineStore("query", () => {
}
const tableStructureRefreshVersions = ref<Record<string, number>>({});
function tableStructureKey(
connectionId: string,
database: string,
schema: string | undefined,
tableName: string,
): string {
function tableStructureKey(connectionId: string, database: string, schema: string | undefined, tableName: string): string {
return [connectionId, database, schema || "", tableName].map((part) => part.toLowerCase()).join("\u0000");
}
function invalidateTableStructure(
connectionId: string,
database: string,
schema: string | undefined,
tableName: string,
) {
function invalidateTableStructure(connectionId: string, database: string, schema: string | undefined, tableName: string) {
if (!tableName) return;
const key = tableStructureKey(connectionId, database, schema, tableName);
tableStructureRefreshVersions.value = {
@@ -160,12 +130,7 @@ export const useQueryStore = defineStore("query", () => {
};
}
function tableStructureRefreshVersion(
connectionId: string,
database: string,
schema: string | undefined,
tableName: string,
): number {
function tableStructureRefreshVersion(connectionId: string, database: string, schema: string | undefined, tableName: string): number {
return tableStructureRefreshVersions.value[tableStructureKey(connectionId, database, schema, tableName)] ?? 0;
}
const MAX_CACHED_RESULTS = 5;
@@ -270,30 +235,11 @@ export const useQueryStore = defineStore("query", () => {
{ flush: "post" },
);
function findTabByIdentity(
connectionId: string,
database: string,
title: string,
mode: QueryTab["mode"],
schema?: string,
) {
return tabs.value.find(
(tab) =>
tab.connectionId === connectionId &&
tab.database === database &&
tab.title === title &&
tab.mode === mode &&
(tab.schema || "") === (schema || ""),
);
function findTabByIdentity(connectionId: string, database: string, title: string, mode: QueryTab["mode"], schema?: string) {
return tabs.value.find((tab) => tab.connectionId === connectionId && tab.database === database && tab.title === title && tab.mode === mode && (tab.schema || "") === (schema || ""));
}
function createTab(
connectionId: string,
database: string,
title?: string,
mode: QueryTab["mode"] = "query",
schema?: string,
) {
function createTab(connectionId: string, database: string, title?: string, mode: QueryTab["mode"] = "query", schema?: string) {
if (title) {
const existing = findTabByIdentity(connectionId, database, title, mode, schema);
if (existing) {
@@ -323,13 +269,7 @@ export const useQueryStore = defineStore("query", () => {
function openObjectBrowser(connectionId: string, database: string, schema?: string) {
const title = schema ? `${schema} objects` : `${database} objects`;
const existing = tabs.value.find(
(tab) =>
tab.mode === "objects" &&
tab.connectionId === connectionId &&
tab.database === database &&
(tab.objectBrowser?.schema || "") === (schema || ""),
);
const existing = tabs.value.find((tab) => tab.mode === "objects" && tab.connectionId === connectionId && tab.database === database && (tab.objectBrowser?.schema || "") === (schema || ""));
if (existing) {
activeTabId.value = existing.id;
return existing.id;
@@ -385,22 +325,14 @@ export const useQueryStore = defineStore("query", () => {
function openTableStructure(connectionId: string, database: string, schema?: string, tableName?: string) {
const resolvedTableName = tableName || "";
if (resolvedTableName) {
const existing = tabs.value.find(
(tab) =>
tab.mode === "structure" &&
tab.connectionId === connectionId &&
tab.database === database &&
(tab.structureTableName || "") === resolvedTableName,
);
const existing = tabs.value.find((tab) => tab.mode === "structure" && tab.connectionId === connectionId && tab.database === database && (tab.structureTableName || "") === resolvedTableName);
if (existing) {
activeTabId.value = existing.id;
return existing.id;
}
}
const title = resolvedTableName
? t("structureEditor.editTabTitle", { tableName: resolvedTableName })
: t("structureEditor.createTitle");
const title = resolvedTableName ? t("structureEditor.editTabTitle", { tableName: resolvedTableName }) : t("structureEditor.createTitle");
const id = uuid();
const tab: QueryTab = {
id,
@@ -703,10 +635,7 @@ export const useQueryStore = defineStore("query", () => {
await executeTabSql(activeTabId.value, sql, { resultBaseSql: sql, resultSortedSql: undefined });
}
type QueryMetadataPatch = Pick<
QueryTab,
"queryAnalysis" | "querySourceColumns" | "queryEditabilityReason" | "tableMeta"
>;
type QueryMetadataPatch = Pick<QueryTab, "queryAnalysis" | "querySourceColumns" | "queryEditabilityReason" | "tableMeta">;
function applyQueryMetadataPatch(tab: QueryTab, patch: QueryMetadataPatch) {
tab.queryAnalysis = patch.queryAnalysis;
@@ -715,12 +644,7 @@ export const useQueryStore = defineStore("query", () => {
tab.tableMeta = patch.tableMeta;
}
async function buildQueryMetadataPatch(
tab: QueryTab,
sql: string,
traceId?: string,
elapsed?: () => string,
): Promise<QueryMetadataPatch | undefined> {
async function buildQueryMetadataPatch(tab: QueryTab, sql: string, traceId?: string, elapsed?: () => string): Promise<QueryMetadataPatch | undefined> {
if (tab.mode !== "query") return;
if (!tab.result || !tab.result.columns.length) {
return {
@@ -767,23 +691,9 @@ export const useQueryStore = defineStore("query", () => {
if (dbType === "postgres" || dbType === "kwdb") schema = "public";
else schema = "";
}
const metadataSchema =
normalizeOracleLikeMetadataIdentifier(
dbType,
schema || undefined,
analysis.schema ? analysis.schemaQuoted : false,
) || "";
const metadataTableName = normalizeOracleLikeMetadataIdentifier(
dbType,
analysis.tableName,
analysis.tableNameQuoted,
)!;
const metadataAnalysis = normalizeOracleLikeQueryAnalysis(
dbType,
analysis,
metadataSchema || undefined,
metadataTableName,
);
const metadataSchema = normalizeOracleLikeMetadataIdentifier(dbType, schema || undefined, analysis.schema ? analysis.schemaQuoted : false) || "";
const metadataTableName = normalizeOracleLikeMetadataIdentifier(dbType, analysis.tableName, analysis.tableNameQuoted)!;
const metadataAnalysis = normalizeOracleLikeQueryAnalysis(dbType, analysis, metadataSchema || undefined, metadataTableName);
try {
console.info("[DBX][executeTabSql:metadata:get-columns:start]", {
@@ -850,13 +760,7 @@ export const useQueryStore = defineStore("query", () => {
}
}
function analyzeQueryMetadataInBackground(
tabId: string,
sql: string,
result: QueryResult,
traceId: string,
elapsed: () => string,
) {
function analyzeQueryMetadataInBackground(tabId: string, sql: string, result: QueryResult, traceId: string, elapsed: () => string) {
void (async () => {
const tab = tabs.value.find((t) => t.id === tabId);
if (!tab || tab.result !== result) return;
@@ -872,12 +776,7 @@ export const useQueryStore = defineStore("query", () => {
})();
}
function setQueryTotalRowCountIfCurrent(
tabId: string,
executionId: string,
result: QueryResult,
totalRowCount: number | undefined,
) {
function setQueryTotalRowCountIfCurrent(tabId: string, executionId: string, result: QueryResult, totalRowCount: number | undefined) {
const current = tabs.value.find((t) => t.id === tabId);
if (current?.mode !== "query") return;
if (current.executionId !== executionId && current.result !== result) return;
@@ -885,20 +784,7 @@ export const useQueryStore = defineStore("query", () => {
current.resultTotalRowCountLoading = false;
}
function countQueryTotalRowsInBackground(options: {
tabId: string;
connectionId: string;
database: string;
schema?: string;
countSql?: string;
result: QueryResult;
pageLimit?: number;
pageOffset?: number;
executionId: string;
traceId: string;
elapsed: () => string;
timeoutSecs: number;
}) {
function countQueryTotalRowsInBackground(options: { tabId: string; connectionId: string; database: string; schema?: string; countSql?: string; result: QueryResult; pageLimit?: number; pageOffset?: number; executionId: string; traceId: string; elapsed: () => string; timeoutSecs: number }) {
const resultRowCount = options.result.rows.length;
if (!options.countSql || resultRowCount <= 0) {
setQueryTotalRowCountIfCurrent(options.tabId, options.executionId, options.result, undefined);
@@ -907,26 +793,14 @@ export const useQueryStore = defineStore("query", () => {
const countSql = options.countSql;
if (typeof options.pageLimit === "number" && resultRowCount < options.pageLimit) {
setQueryTotalRowCountIfCurrent(
options.tabId,
options.executionId,
options.result,
(options.pageOffset ?? 0) + resultRowCount,
);
setQueryTotalRowCountIfCurrent(options.tabId, options.executionId, options.result, (options.pageOffset ?? 0) + resultRowCount);
return;
}
void (async () => {
try {
console.info("[DBX][executeTabSql:count:start]", { traceId: options.traceId, elapsed: options.elapsed() });
const countResult = await api.executeQuery(
options.connectionId,
options.database,
countSql,
options.schema,
undefined,
{ timeoutSecs: options.timeoutSecs },
);
const countResult = await api.executeQuery(options.connectionId, options.database, countSql, options.schema, undefined, { timeoutSecs: options.timeoutSecs });
const total = Number(countResult.rows?.[0]?.[0] ?? 0);
if (!Number.isFinite(total) || total < 0) {
setQueryTotalRowCountIfCurrent(options.tabId, options.executionId, options.result, undefined);
@@ -1029,15 +903,7 @@ export const useQueryStore = defineStore("query", () => {
if (mongoFind) {
await connStore.ensureConnected(tab.connectionId);
console.info("[DBX][executeTabSql:mongo-find:start]", { traceId, collection: mongoFind.collection });
const result = await api.mongoFindDocuments(
tab.connectionId,
tab.database,
mongoFind.collection,
mongoFind.skip,
mongoFind.limit,
mongoFind.filter,
mongoFind.sort,
);
const result = await api.mongoFindDocuments(tab.connectionId, tab.database, mongoFind.collection, mongoFind.skip, mongoFind.limit, mongoFind.filter, mongoFind.sort);
console.info("[DBX][executeTabSql:mongo-find:done]", {
traceId,
rowCount: result.documents.length,
@@ -1048,9 +914,7 @@ export const useQueryStore = defineStore("query", () => {
if (current?.executionId === executionId) {
current.results = undefined;
current.activeResultIndex = undefined;
current.result = markQueryResultRowsRaw(
mongoDocumentsToQueryResult(result.documents, performance.now() - startedAt, result.total),
);
current.result = markQueryResultRowsRaw(mongoDocumentsToQueryResult(result.documents, performance.now() - startedAt, result.total));
touchResult(current);
current.queryAnalysis = undefined;
current.querySourceColumns = undefined;
@@ -1065,14 +929,7 @@ export const useQueryStore = defineStore("query", () => {
if (mongoCount) {
await connStore.ensureConnected(tab.connectionId);
console.info("[DBX][executeTabSql:mongo-count:start]", { traceId, collection: mongoCount.collection });
const result = await api.mongoFindDocuments(
tab.connectionId,
tab.database,
mongoCount.collection,
0,
1,
mongoCount.filter,
);
const result = await api.mongoFindDocuments(tab.connectionId, tab.database, mongoCount.collection, 0, 1, mongoCount.filter);
console.info("[DBX][executeTabSql:mongo-count:done]", {
traceId,
total: result.total,
@@ -1102,13 +959,7 @@ export const useQueryStore = defineStore("query", () => {
}
await connStore.ensureConnected(tab.connectionId);
console.info("[DBX][executeTabSql:mongo-aggregate:start]", { traceId, collection: mongoAggregate.collection });
const result = await api.mongoAggregateDocuments(
tab.connectionId,
tab.database,
mongoAggregate.collection,
mongoAggregate.pipeline,
pageLimit,
);
const result = await api.mongoAggregateDocuments(tab.connectionId, tab.database, mongoAggregate.collection, mongoAggregate.pipeline, pageLimit);
console.info("[DBX][executeTabSql:mongo-aggregate:done]", {
traceId,
rowCount: result.documents.length,
@@ -1119,9 +970,7 @@ export const useQueryStore = defineStore("query", () => {
if (current?.executionId === executionId) {
current.results = undefined;
current.activeResultIndex = undefined;
current.result = markQueryResultRowsRaw(
mongoDocumentsToQueryResult(result.documents, performance.now() - startedAt, result.total),
);
current.result = markQueryResultRowsRaw(mongoDocumentsToQueryResult(result.documents, performance.now() - startedAt, result.total));
touchResult(current);
current.queryAnalysis = undefined;
current.querySourceColumns = undefined;
@@ -1169,31 +1018,13 @@ export const useQueryStore = defineStore("query", () => {
});
let affectedRows = 0;
if (mongoWrite.kind === "insert") {
const result = await api.mongoInsertDocuments(
tab.connectionId,
tab.database,
mongoWrite.collection,
mongoWrite.docsJson,
);
const result = await api.mongoInsertDocuments(tab.connectionId, tab.database, mongoWrite.collection, mongoWrite.docsJson);
affectedRows = result.affected_rows;
} else if (mongoWrite.kind === "update") {
const result = await api.mongoUpdateDocuments(
tab.connectionId,
tab.database,
mongoWrite.collection,
mongoWrite.filter,
mongoWrite.update,
mongoWrite.many,
);
const result = await api.mongoUpdateDocuments(tab.connectionId, tab.database, mongoWrite.collection, mongoWrite.filter, mongoWrite.update, mongoWrite.many);
affectedRows = result.affected_rows;
} else {
const result = await api.mongoDeleteDocuments(
tab.connectionId,
tab.database,
mongoWrite.collection,
mongoWrite.filter,
mongoWrite.many,
);
const result = await api.mongoDeleteDocuments(tab.connectionId, tab.database, mongoWrite.collection, mongoWrite.filter, mongoWrite.many);
affectedRows = result.affected_rows;
}
console.info("[DBX][executeTabSql:mongo-write:done]", {
@@ -1233,27 +1064,10 @@ export const useQueryStore = defineStore("query", () => {
...(clientSessionId ? { clientSessionId } : {}),
timeoutSecs: queryTimeoutSecs,
};
const executionSchema = connectionUsesSchemaExecutionContext(conn)
? tab.schema || tab.database
: tab.mode === "data" || connectionUsesDatabaseObjectTreeMode(conn)
? undefined
: tab.schema;
const executionPromise = api.executeMulti(
tab.connectionId,
tab.database,
sqlToExecute,
executionSchema,
executionId,
executionOptions,
);
const executionSchema = connectionUsesSchemaExecutionContext(conn) ? tab.schema || tab.database : tab.mode === "data" || connectionUsesDatabaseObjectTreeMode(conn) ? undefined : tab.schema;
const executionPromise = api.executeMulti(tab.connectionId, tab.database, sqlToExecute, executionSchema, executionId, executionOptions);
const frontendTimeoutSecs = Math.max(queryTimeoutSecs * 2, 60);
const results = markQueryResultsRowsRaw(
await withFrontendQueryTimeout(
executionPromise,
queryTimeoutSecs === 0 ? 0 : frontendTimeoutSecs,
t("editor.queryTimeoutError", { seconds: frontendTimeoutSecs }),
),
);
const results = markQueryResultsRowsRaw(await withFrontendQueryTimeout(executionPromise, queryTimeoutSecs === 0 ? 0 : frontendTimeoutSecs, t("editor.queryTimeoutError", { seconds: frontendTimeoutSecs })));
console.info("[DBX][executeTabSql:execute-multi:done]", {
traceId,
resultCount: results.length,
@@ -1289,13 +1103,7 @@ export const useQueryStore = defineStore("query", () => {
// the Elasticsearch driver) already reports the true match total via
// affected_rows. Use it directly so the result-grid can compute the
// page count without issuing a separate COUNT query.
if (
current.result &&
current.mode === "query" &&
typeof pageLimit === "number" &&
!countSql &&
typeof current.result.affected_rows === "number"
) {
if (current.result && current.mode === "query" && typeof pageLimit === "number" && !countSql && typeof current.result.affected_rows === "number") {
current.resultTotalRowCount = current.result.affected_rows;
current.resultTotalRowCountLoading = false;
}
@@ -1324,8 +1132,7 @@ export const useQueryStore = defineStore("query", () => {
backendMs: current.result?.execution_time_ms,
elapsed: elapsed(),
});
if (current.mode === "query" && current.result)
analyzeQueryMetadataInBackground(id, queryBaseSql, current.result, traceId, elapsed);
if (current.mode === "query" && current.result) analyzeQueryMetadataInBackground(id, queryBaseSql, current.result, traceId, elapsed);
} else {
console.warn("[DBX][executeTabSql:stale-result]", {
traceId,
@@ -1403,9 +1210,7 @@ export const useQueryStore = defineStore("query", () => {
}
try {
const mode = explainMode === "autotrace" ? "autotrace" : "explain";
const planText = (await api.getExplainInfo(tab.connectionId, tab.database, tab.schema, sql, mode)) as
| string
| undefined;
const planText = (await api.getExplainInfo(tab.connectionId, tab.database, tab.schema, sql, mode)) as string | undefined;
const current = tabs.value.find((t) => t.id === id);
if (current?.explainExecutionId === executionId) {
if (planText && planText.length > 0) {
@@ -1536,9 +1341,7 @@ export const useQueryStore = defineStore("query", () => {
}
async function trimResultCache() {
const inactive = tabs.value
.filter((t) => t.id !== activeTabId.value && (t.result || t.results))
.sort((a, b) => (a.resultAccessedAt ?? 0) - (b.resultAccessedAt ?? 0));
const inactive = tabs.value.filter((t) => t.id !== activeTabId.value && (t.result || t.results)).sort((a, b) => (a.resultAccessedAt ?? 0) - (b.resultAccessedAt ?? 0));
if (inactive.length > MAX_CACHED_RESULTS) {
const toEvict = inactive.slice(0, inactive.length - MAX_CACHED_RESULTS);
await Promise.all(toEvict.map((t) => evictCachedResult(t)));
@@ -1555,11 +1358,7 @@ export const useQueryStore = defineStore("query", () => {
const activeIndex = snapshot.activeResultIndex ?? 0;
tab.results = results;
tab.activeResultIndex = snapshot.activeResultIndex;
tab.result = snapshot.result
? markQueryResultRowsRaw(snapshot.result)
: results?.[activeIndex]
? markQueryResultRowsRaw(results[activeIndex])
: undefined;
tab.result = snapshot.result ? markQueryResultRowsRaw(snapshot.result) : results?.[activeIndex] ? markQueryResultRowsRaw(results[activeIndex]) : undefined;
if (!tab.result && !tab.results) return false;
tab.queryAnalysis = snapshot.queryAnalysis;
@@ -1617,17 +1416,9 @@ export const useQueryStore = defineStore("query", () => {
const pageLimit = TABLE_DATA_EXPORT_PAGE_SIZE;
const effectiveDbType = effectiveDatabaseTypeForConnection(conn);
const primaryKeys = tab.tableMeta
? editablePrimaryKeys(effectiveDbType, tab.tableMeta.columns)
: tableMeta.primaryKeys;
const fallbackOrderColumns =
effectiveDbType === "sqlserver" && !primaryKeys.length
? tableMeta.columns.slice(0, 1).map((column) => column.name)
: undefined;
const sortOrder =
tab.resultSortColumn && tab.resultSortDirection
? `${quoteTableIdentifier(effectiveDbType, tab.resultSortColumn)} ${tab.resultSortDirection.toUpperCase()}`
: undefined;
const primaryKeys = tab.tableMeta ? editablePrimaryKeys(effectiveDbType, tab.tableMeta.columns) : tableMeta.primaryKeys;
const fallbackOrderColumns = effectiveDbType === "sqlserver" && !primaryKeys.length ? tableMeta.columns.slice(0, 1).map((column) => column.name) : undefined;
const sortOrder = tab.resultSortColumn && tab.resultSortDirection ? `${quoteTableIdentifier(effectiveDbType, tab.resultSortColumn)} ${tab.resultSortDirection.toUpperCase()}` : undefined;
const orderBy = tab.orderByInput?.trim() || sortOrder;
const queryTimeoutSecs = queryTimeoutSecsForConnection(conn);
const rows: QueryResult["rows"] = [];
@@ -1712,23 +1503,14 @@ export const useQueryStore = defineStore("query", () => {
timeoutSecs: queryTimeoutSecs,
}
: { maxRows: plan.pageLimit, fetchSize: plan.pageLimit, timeoutSecs: queryTimeoutSecs };
const results = await api.executeMulti(
tab.connectionId,
tab.database,
plan.sqlToExecute,
tab.schema,
undefined,
executionOptions,
);
const results = await api.executeMulti(tab.connectionId, tab.database, plan.sqlToExecute, tab.schema, undefined, executionOptions);
const result = results[0];
if (!result) break;
if (columns.length === 0) columns = result.columns;
rows.push(...result.rows);
executionTimeMs += result.execution_time_ms ?? 0;
sessionId = result.session_id ?? undefined;
const shouldFetchNextPage = plan.useAgentResultSession
? result.has_more === true
: result.rows.length >= plan.pageLimit;
const shouldFetchNextPage = plan.useAgentResultSession ? result.has_more === true : result.rows.length >= plan.pageLimit;
if (!shouldFetchNextPage) break;
offset += result.rows.length;
}