feat: show username/password fields for Access database connections
This commit is contained in:
1 parent
2e021d37d1
commit
edba8214b5
477 files changed
+5720
-19773
No files matched your search
@@ -1,34 +1,16 @@
|
||||
import { shallowRef, onBeforeUnmount, type ShallowRef, createApp, watch } from "vue";
|
||||
import { EditorState, Compartment } from "@codemirror/state";
|
||||
import {
|
||||
EditorView,
|
||||
keymap,
|
||||
drawSelection,
|
||||
dropCursor,
|
||||
highlightSpecialChars,
|
||||
highlightActiveLine,
|
||||
} from "@codemirror/view";
|
||||
import { EditorView, keymap, drawSelection, dropCursor, highlightSpecialChars, highlightActiveLine } from "@codemirror/view";
|
||||
import { json } from "@codemirror/lang-json";
|
||||
import { search as cmSearch } from "@codemirror/search";
|
||||
import { defaultKeymap, history, historyKeymap } from "@codemirror/commands";
|
||||
import { bracketMatching } from "@codemirror/language";
|
||||
import { trimmedSelectionLayer } from "@/lib/codemirrorTrimmedSelectionLayer";
|
||||
import {
|
||||
EDITOR_FONT_FAMILY_CSS_VAR,
|
||||
EDITOR_FONT_SIZE_CSS_VAR,
|
||||
cellDetailActiveLineColor,
|
||||
loadEditorTheme,
|
||||
editorFontTheme,
|
||||
} from "@/lib/editorThemes";
|
||||
import { EDITOR_FONT_FAMILY_CSS_VAR, EDITOR_FONT_SIZE_CSS_VAR, cellDetailActiveLineColor, loadEditorTheme, editorFontTheme } from "@/lib/editorThemes";
|
||||
import { shortcutToCodeMirrorKey } from "@/lib/shortcutRegistry";
|
||||
import { useSettingsStore } from "@/stores/settingsStore";
|
||||
import { CELL_DETAIL_JSON_FORMAT_MAX_LENGTH, isJsonColumnType } from "@/lib/cellDetailPresentation";
|
||||
import {
|
||||
clampEditorFontSize,
|
||||
createEditorZoomCommitScheduler,
|
||||
fontSizeFromGestureScale,
|
||||
fontSizeFromWheelDelta,
|
||||
} from "@/lib/editorZoom";
|
||||
import { clampEditorFontSize, createEditorZoomCommitScheduler, fontSizeFromGestureScale, fontSizeFromWheelDelta } from "@/lib/editorZoom";
|
||||
import i18n from "@/i18n";
|
||||
import EditorSearchPanel from "@/components/editor/EditorSearchPanel.vue";
|
||||
import type { EditorTheme } from "@/stores/settingsStore";
|
||||
@@ -147,25 +129,19 @@ export function useCellDetailEditor(options: UseCellDetailEditorOptions): UseCel
|
||||
zoomCommitScheduler.flush(liveFontSize);
|
||||
}
|
||||
|
||||
watch(
|
||||
[() => options.fontSize(), () => options.fontFamily(), () => options.editorTheme(), () => options.appAppearance()],
|
||||
async ([fontSize, fontFamily, editorTheme, appearance]) => {
|
||||
const editor = view.value;
|
||||
if (!editor || destroyed) return;
|
||||
if (!isGestureZooming && !zoomCommitScheduler.hasPendingCommit()) {
|
||||
liveFontSize = clampEditorFontSize(fontSize);
|
||||
}
|
||||
syncEditorFontCssVars(liveFontSize, fontFamily);
|
||||
const theme = await loadEditorTheme(editorTheme, appearance);
|
||||
if (!view.value || destroyed) return;
|
||||
view.value.dispatch({
|
||||
effects: [
|
||||
themeComp.reconfigure(theme),
|
||||
fontThemeComp.reconfigure(editorFontTheme(EditorView, liveFontSize, fontFamily, { scrollable: false })),
|
||||
],
|
||||
});
|
||||
},
|
||||
);
|
||||
watch([() => options.fontSize(), () => options.fontFamily(), () => options.editorTheme(), () => options.appAppearance()], async ([fontSize, fontFamily, editorTheme, appearance]) => {
|
||||
const editor = view.value;
|
||||
if (!editor || destroyed) return;
|
||||
if (!isGestureZooming && !zoomCommitScheduler.hasPendingCommit()) {
|
||||
liveFontSize = clampEditorFontSize(fontSize);
|
||||
}
|
||||
syncEditorFontCssVars(liveFontSize, fontFamily);
|
||||
const theme = await loadEditorTheme(editorTheme, appearance);
|
||||
if (!view.value || destroyed) return;
|
||||
view.value.dispatch({
|
||||
effects: [themeComp.reconfigure(theme), fontThemeComp.reconfigure(editorFontTheme(EditorView, liveFontSize, fontFamily, { scrollable: false }))],
|
||||
});
|
||||
});
|
||||
|
||||
async function create(parent: HTMLElement, initialValue: string, columnType?: string): Promise<void> {
|
||||
if (destroyed) return;
|
||||
|
||||
@@ -23,23 +23,15 @@ export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>)
|
||||
return quoteTableIdentifier(effectiveDatabaseTypeForConnection(config), name);
|
||||
}
|
||||
|
||||
function buildTableSql(
|
||||
tab: QueryTab,
|
||||
options: { orderBy?: string; limit?: number; offset?: number; whereInput?: string } = {},
|
||||
): Promise<string> {
|
||||
function buildTableSql(tab: QueryTab, options: { orderBy?: string; limit?: number; offset?: number; whereInput?: string } = {}): Promise<string> {
|
||||
const config = connectionStore.getConfig(tab.connectionId);
|
||||
const effectiveDbType = effectiveDatabaseTypeForConnection(config);
|
||||
const tableMeta = tableMetaForDataTab(tab);
|
||||
const primaryKeys = tab.tableMeta
|
||||
? editablePrimaryKeys(effectiveDbType, tab.tableMeta.columns)
|
||||
: (tableMeta?.primaryKeys ?? []);
|
||||
const primaryKeys = tab.tableMeta ? editablePrimaryKeys(effectiveDbType, tab.tableMeta.columns) : (tableMeta?.primaryKeys ?? []);
|
||||
if (tab.tableMeta && primaryKeys.join("\0") !== tab.tableMeta.primaryKeys.join("\0")) {
|
||||
tab.tableMeta.primaryKeys = primaryKeys;
|
||||
}
|
||||
const fallbackOrderColumns =
|
||||
effectiveDbType === "sqlserver" && !primaryKeys.length
|
||||
? tableMeta?.columns.slice(0, 1).map((column) => column.name)
|
||||
: undefined;
|
||||
const fallbackOrderColumns = effectiveDbType === "sqlserver" && !primaryKeys.length ? tableMeta?.columns.slice(0, 1).map((column) => column.name) : undefined;
|
||||
const useRowId = usesSyntheticRowIdKey(effectiveDbType, primaryKeys);
|
||||
return buildTableSelectSql({
|
||||
databaseType: effectiveDbType,
|
||||
@@ -61,14 +53,7 @@ export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>)
|
||||
await queryStore.executeTabSql(tab.id, sql, { preserveResultDuringExecution: true });
|
||||
}
|
||||
|
||||
async function onReloadData(
|
||||
sql?: string,
|
||||
_searchText?: string,
|
||||
whereInput?: string,
|
||||
orderBy?: string,
|
||||
limit?: number,
|
||||
offset?: number,
|
||||
) {
|
||||
async function onReloadData(sql?: string, _searchText?: string, whereInput?: string, orderBy?: string, limit?: number, offset?: number) {
|
||||
const tab = activeTab.value;
|
||||
if (!tab) return;
|
||||
if (tab.mode === "data" && tableMetaForDataTab(tab)) {
|
||||
@@ -110,10 +95,7 @@ export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>)
|
||||
const baseSql = tab.resultSortedSql ?? tab.resultBaseSql ?? tab.lastExecutedSql ?? tab.sql;
|
||||
if (!baseSql.trim()) return;
|
||||
const expectedNextOffset = (tab.resultPageOffset ?? 0) + (tab.resultPageLimit ?? limit);
|
||||
const sessionId =
|
||||
tab.result?.has_more && tab.result?.session_id && offset === expectedNextOffset && limit === tab.resultPageLimit
|
||||
? tab.result.session_id
|
||||
: undefined;
|
||||
const sessionId = tab.result?.has_more && tab.result?.session_id && offset === expectedNextOffset && limit === tab.resultPageLimit ? tab.result.session_id : undefined;
|
||||
await queryStore.executeTabSql(tab.id, baseSql, {
|
||||
resultBaseSql: tab.resultBaseSql ?? tab.sql,
|
||||
resultSortedSql: tab.resultSortedSql,
|
||||
@@ -146,9 +128,7 @@ export function useDataGridActions(activeTab: ComputedRef<QueryTab | undefined>)
|
||||
tab.whereInput = whereInput ?? "";
|
||||
const config = connectionStore.getConfig(tab.connectionId);
|
||||
const quotedColumn = quoteIdent(tab, column);
|
||||
const orderBy = direction
|
||||
? `${config?.db_type === "neo4j" ? `n.${quotedColumn}` : quotedColumn} ${direction.toUpperCase()}`
|
||||
: undefined;
|
||||
const orderBy = direction ? `${config?.db_type === "neo4j" ? `n.${quotedColumn}` : quotedColumn} ${direction.toUpperCase()}` : undefined;
|
||||
const sql = await buildTableSql(tab, { orderBy, whereInput });
|
||||
queryStore.updateSql(tab.id, sql);
|
||||
await queryStore.executeTabSql(tab.id, sql, { preserveResultDuringExecution: true });
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
import { ref, computed, type ComputedRef, type Ref } from "vue";
|
||||
import { useElementSize } from "@vueuse/core";
|
||||
import {
|
||||
calculateDataGridColumnWidth,
|
||||
DATA_GRID_COL_MIN_WIDTH,
|
||||
DATA_GRID_SAMPLE_ROWS,
|
||||
} from "@/lib/dataGridColumnWidth";
|
||||
import { calculateDataGridColumnWidth, DATA_GRID_COL_MIN_WIDTH, DATA_GRID_SAMPLE_ROWS } from "@/lib/dataGridColumnWidth";
|
||||
|
||||
type CellValue = string | number | boolean | null;
|
||||
|
||||
|
||||
@@ -1,16 +1,4 @@
|
||||
import {
|
||||
ref,
|
||||
computed,
|
||||
nextTick,
|
||||
watch,
|
||||
getCurrentInstance,
|
||||
onActivated,
|
||||
onBeforeUnmount,
|
||||
onDeactivated,
|
||||
onMounted,
|
||||
type ComputedRef,
|
||||
type Ref,
|
||||
} from "vue";
|
||||
import { ref, computed, nextTick, watch, getCurrentInstance, onActivated, onBeforeUnmount, onDeactivated, onMounted, type ComputedRef, type Ref } from "vue";
|
||||
import * as api from "@/lib/api";
|
||||
import type { CellValue } from "@/lib/cellValue";
|
||||
import { coerceDataGridCellValue, dataGridCellEditorText } from "@/lib/dataGridCellCoercion";
|
||||
@@ -60,16 +48,7 @@ export interface UseDataGridEditorOptions {
|
||||
sourceColumns?: ComputedRef<Array<string | undefined> | undefined>;
|
||||
canEditExistingRows?: ComputedRef<boolean>;
|
||||
onExecuteSql: ComputedRef<((sql: string) => Promise<void>) | undefined>;
|
||||
customSave?: ComputedRef<
|
||||
| ((changes: {
|
||||
dirtyRows: Map<number, Map<number, CellValue>>;
|
||||
newRows: CellValue[][];
|
||||
deletedRows: Set<number>;
|
||||
columns: string[];
|
||||
rows: CellValue[][];
|
||||
}) => Promise<void>)
|
||||
| undefined
|
||||
>;
|
||||
customSave?: ComputedRef<((changes: { dirtyRows: Map<number, Map<number, CellValue>>; newRows: CellValue[][]; deletedRows: Set<number>; columns: string[]; rows: CellValue[][] }) => Promise<void>) | undefined>;
|
||||
sql: ComputedRef<string | undefined>;
|
||||
searchText: Ref<string>;
|
||||
whereFilterInput: Ref<string>;
|
||||
@@ -82,15 +61,7 @@ export interface UseDataGridEditorOptions {
|
||||
currentPage: Ref<number>;
|
||||
cacheKey?: ComputedRef<string | undefined>;
|
||||
emit: {
|
||||
(
|
||||
event: "reload",
|
||||
sql?: string,
|
||||
searchText?: string,
|
||||
whereInput?: string,
|
||||
orderBy?: string,
|
||||
limit?: number,
|
||||
offset?: number,
|
||||
): void;
|
||||
(event: "reload", sql?: string, searchText?: string, whereInput?: string, orderBy?: string, limit?: number, offset?: number): void;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -203,12 +174,7 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
const isSaving = ref(false);
|
||||
const saveError = ref("");
|
||||
|
||||
const useTransaction = computed(
|
||||
() =>
|
||||
editable.value &&
|
||||
supportsDataGridTransaction(databaseType.value) &&
|
||||
(!!customSave?.value || (!!connectionId.value && !!database.value && !!tableMeta.value)),
|
||||
);
|
||||
const useTransaction = computed(() => editable.value && supportsDataGridTransaction(databaseType.value) && (!!customSave?.value || (!!connectionId.value && !!database.value && !!tableMeta.value)));
|
||||
|
||||
if (hasPendingChanges.value && useTransaction.value) {
|
||||
transactionActive.value = true;
|
||||
@@ -543,9 +509,7 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
}
|
||||
|
||||
function clonedRowData(item: RowItem): CellValue[] {
|
||||
const columnInfoByName = new Map(
|
||||
(tableMeta.value?.columns ?? []).map((column) => [column.name.toLowerCase(), column]),
|
||||
);
|
||||
const columnInfoByName = new Map((tableMeta.value?.columns ?? []).map((column) => [column.name.toLowerCase(), column]));
|
||||
return item.data.map((val, i) => {
|
||||
const columnName = result.value.columns[i];
|
||||
const columnInfo = columnInfoByName.get(columnName.toLowerCase());
|
||||
@@ -558,9 +522,7 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
if (databaseType.value === "neo4j" && columnName === DBX_NEO4J_ELEMENT_ID_COLUMN) return true;
|
||||
const extra = columnInfo?.extra ?? "";
|
||||
const columnDefault = columnInfo?.column_default ?? "";
|
||||
return (
|
||||
/\b(auto_increment|autoincrement|identity|generated)\b/i.test(extra) || /\bnextval\s*\(/i.test(columnDefault)
|
||||
);
|
||||
return /\b(auto_increment|autoincrement|identity|generated)\b/i.test(extra) || /\bnextval\s*\(/i.test(columnDefault);
|
||||
}
|
||||
|
||||
function cloneRow(rowId: number) {
|
||||
@@ -663,9 +625,7 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
columns: result.value.columns,
|
||||
sourceColumns: sourceColumns.value,
|
||||
rows: result.value.rows,
|
||||
dirtyRows: [...dirtyRows.value.entries()].map(
|
||||
([rowIndex, changes]) => [rowIndex, [...changes.entries()]] as [number, Array<[number, CellValue]>],
|
||||
),
|
||||
dirtyRows: [...dirtyRows.value.entries()].map(([rowIndex, changes]) => [rowIndex, [...changes.entries()]] as [number, Array<[number, CellValue]>]),
|
||||
deletedRows: [...deletedRows.value],
|
||||
newRows: newRows.value,
|
||||
};
|
||||
@@ -677,20 +637,11 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
}
|
||||
|
||||
function dataChangeOperation() {
|
||||
const operations = [
|
||||
newRows.value.length > 0 ? "INSERT" : "",
|
||||
dirtyRows.value.size > 0 ? "UPDATE" : "",
|
||||
deletedRows.value.size > 0 ? "DELETE" : "",
|
||||
].filter(Boolean);
|
||||
const operations = [newRows.value.length > 0 ? "INSERT" : "", dirtyRows.value.size > 0 ? "UPDATE" : "", deletedRows.value.size > 0 ? "DELETE" : ""].filter(Boolean);
|
||||
return operations.length === 1 ? operations[0] : "DATA CHANGE";
|
||||
}
|
||||
|
||||
async function recordDataGridHistory(
|
||||
statements: string[],
|
||||
rollbackStatements: string[],
|
||||
elapsed: number,
|
||||
historyResult?: { affected_rows?: number; success?: boolean; error?: string },
|
||||
) {
|
||||
async function recordDataGridHistory(statements: string[], rollbackStatements: string[], elapsed: number, historyResult?: { affected_rows?: number; success?: boolean; error?: string }) {
|
||||
if (!connectionId.value || !database.value || !tableMeta.value) return;
|
||||
const connName = connectionStore.getConfig(connectionId.value)?.name || "";
|
||||
const success = historyResult?.success ?? true;
|
||||
@@ -721,12 +672,7 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
});
|
||||
}
|
||||
|
||||
async function recordFailedDataGridHistory(
|
||||
statements: string[],
|
||||
rollbackStatements: string[],
|
||||
start: number,
|
||||
error: unknown,
|
||||
) {
|
||||
async function recordFailedDataGridHistory(statements: string[], rollbackStatements: string[], start: number, error: unknown) {
|
||||
const message = normalizeDataGridSaveError(databaseType.value, error);
|
||||
try {
|
||||
await recordDataGridHistory(statements, rollbackStatements, Date.now() - start, {
|
||||
@@ -740,15 +686,7 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
}
|
||||
|
||||
function reloadCurrentData() {
|
||||
options.emit(
|
||||
"reload",
|
||||
sql.value,
|
||||
searchText.value,
|
||||
options.currentWhereInput.value,
|
||||
orderByInput.value.trim() || undefined,
|
||||
pageSize.value,
|
||||
(currentPage.value - 1) * pageSize.value,
|
||||
);
|
||||
options.emit("reload", sql.value, searchText.value, options.currentWhereInput.value, orderByInput.value.trim() || undefined, pageSize.value, (currentPage.value - 1) * pageSize.value);
|
||||
}
|
||||
|
||||
async function saveChanges() {
|
||||
@@ -808,21 +746,14 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
let apiResult: { affected_rows?: number } | undefined;
|
||||
console.info("[DBX][dataGrid:save-statements]", {
|
||||
databaseType: databaseType.value,
|
||||
table: tableMeta.value
|
||||
? [tableMeta.value.schema, tableMeta.value.tableName].filter(Boolean).join(".")
|
||||
: undefined,
|
||||
table: tableMeta.value ? [tableMeta.value.schema, tableMeta.value.tableName].filter(Boolean).join(".") : undefined,
|
||||
statements: stmts,
|
||||
rollbackStatements: rollbackStmts,
|
||||
});
|
||||
|
||||
if (useTransaction.value && connectionId.value && database.value) {
|
||||
try {
|
||||
apiResult = await api.executeInTransaction(
|
||||
connectionId.value,
|
||||
database.value,
|
||||
stmts,
|
||||
preparedSave?.executionSchema,
|
||||
);
|
||||
apiResult = await api.executeInTransaction(connectionId.value, database.value, stmts, preparedSave?.executionSchema);
|
||||
} catch (e: any) {
|
||||
saveError.value = await recordFailedDataGridHistory(stmts, rollbackStmts, start, e);
|
||||
isSaving.value = false;
|
||||
|
||||
@@ -2,23 +2,12 @@ import { computed, ref, type ComputedRef, type Ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { isTauriRuntime } from "@/lib/tauriRuntime";
|
||||
import * as api from "@/lib/api";
|
||||
import {
|
||||
formatSelectionAsCsv,
|
||||
formatSelectionAsJson,
|
||||
formatSelectionAsSqlInList,
|
||||
formatSelectionAsTsv,
|
||||
type CellSelectionRange,
|
||||
type SelectionData,
|
||||
} from "@/lib/gridSelection";
|
||||
import { formatSelectionAsCsv, formatSelectionAsJson, formatSelectionAsSqlInList, formatSelectionAsTsv, type CellSelectionRange, type SelectionData } from "@/lib/gridSelection";
|
||||
import { useToast } from "@/composables/useToast";
|
||||
import { displayCellValue, type CellValue } from "@/lib/cellValue";
|
||||
import { tryStartExclusiveActivation, type ActionActivationGuard } from "@/lib/actionActivation";
|
||||
import { copyToClipboard } from "@/lib/clipboard";
|
||||
import {
|
||||
buildDataGridCopyInsertStatement,
|
||||
buildDataGridCopyUpdateStatements,
|
||||
type DataGridTableMeta,
|
||||
} from "@/lib/dataGridSql";
|
||||
import { buildDataGridCopyInsertStatement, buildDataGridCopyUpdateStatements, type DataGridTableMeta } from "@/lib/dataGridSql";
|
||||
import { formatSqlInsert } from "@/lib/exportFormats";
|
||||
import { uuid } from "@/lib/utils";
|
||||
import type { DatabaseType, QueryResult } from "@/types/database";
|
||||
@@ -51,9 +40,7 @@ export interface UseDataGridExportOptions {
|
||||
hasCellSelection: ComputedRef<boolean>;
|
||||
selectedCells: ComputedRef<SelectionData>;
|
||||
selectedRange: ComputedRef<CellSelectionRange | null>;
|
||||
contextCell:
|
||||
| Ref<{ rowId: number; rowIndex: number; col: number } | null>
|
||||
| ComputedRef<{ rowId: number; rowIndex: number; col: number } | null>;
|
||||
contextCell: Ref<{ rowId: number; rowIndex: number; col: number } | null> | ComputedRef<{ rowId: number; rowIndex: number; col: number } | null>;
|
||||
getRowItem: (rowId: number) => RowItem | undefined;
|
||||
selectedRowIds: Ref<Set<number>> | ComputedRef<Set<number>>;
|
||||
hasRowSelection: ComputedRef<boolean>;
|
||||
@@ -446,9 +433,7 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
const saveColumns = effectiveColumns(sourceColumns.value, columns.value);
|
||||
const primaryKeySet = new Set(tableMeta.value.primaryKeys.map(normalizeColumnName));
|
||||
const insertableCount = saveColumns.filter(Boolean).length;
|
||||
const insertColumnsCount = saveColumns.filter(
|
||||
(column) => column && !primaryKeySet.has(normalizeColumnName(column)),
|
||||
).length;
|
||||
const insertColumnsCount = saveColumns.filter((column) => column && !primaryKeySet.has(normalizeColumnName(column))).length;
|
||||
return insertColumnsCount > 0 && insertColumnsCount < insertableCount;
|
||||
});
|
||||
|
||||
@@ -616,12 +601,7 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
rowsExported: result.rows.length,
|
||||
};
|
||||
}
|
||||
await api.exportQueryResultXlsx(
|
||||
outputPath,
|
||||
tableMeta.value?.tableName || "Export",
|
||||
result.columns,
|
||||
result.rows,
|
||||
);
|
||||
await api.exportQueryResultXlsx(outputPath, tableMeta.value?.tableName || "Export", result.columns, result.rows);
|
||||
if (needsFullExport && exportProgressState) {
|
||||
exportProgressState.value = {
|
||||
...exportProgressState.value,
|
||||
@@ -644,26 +624,14 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
});
|
||||
}
|
||||
|
||||
async function exportFullTableDataViaBackend(
|
||||
format: "csv" | "xlsx" | "json" | "markdown" | "sql",
|
||||
rowIds?: number[],
|
||||
): Promise<boolean> {
|
||||
async function exportFullTableDataViaBackend(format: "csv" | "xlsx" | "json" | "markdown" | "sql", rowIds?: number[]): Promise<boolean> {
|
||||
const meta = tableMeta.value;
|
||||
if (rowIds?.length || context.value !== "table-data" || !meta || !connectionId.value || !database.value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const extension = format === "markdown" ? "md" : format;
|
||||
const filterName =
|
||||
format === "csv"
|
||||
? "CSV"
|
||||
: format === "xlsx"
|
||||
? "Excel"
|
||||
: format === "json"
|
||||
? "JSON"
|
||||
: format === "markdown"
|
||||
? "Markdown"
|
||||
: "SQL";
|
||||
const filterName = format === "csv" ? "CSV" : format === "xlsx" ? "Excel" : format === "json" ? "JSON" : format === "markdown" ? "Markdown" : "SQL";
|
||||
let outputPath = `${meta.tableName || "export"}.${extension}`;
|
||||
if (isTauriRuntime()) {
|
||||
const { save } = await import("@tauri-apps/plugin-dialog");
|
||||
@@ -756,9 +724,7 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
rows: CellValue[][];
|
||||
} {
|
||||
const exportColumns = tableMeta.value ? effectiveColumns(sourceColumns.value, result.columns) : result.columns;
|
||||
const columnIndexes = exportColumns
|
||||
.map((column, index) => ({ column, index }))
|
||||
.filter((item): item is { column: string; index: number } => !!item.column);
|
||||
const columnIndexes = exportColumns.map((column, index) => ({ column, index })).filter((item): item is { column: string; index: number } => !!item.column);
|
||||
return {
|
||||
columns: columnIndexes.map((item) => item.column),
|
||||
columnTypes: tableMeta.value ? columnIndexes.map((item) => columnTypes.value?.[item.index]) : undefined,
|
||||
@@ -817,10 +783,7 @@ async function saveTextFile(content: string, defaultFileName: string, filterName
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
function effectiveColumns(
|
||||
sourceColumns: Array<string | undefined> | undefined,
|
||||
columns: string[],
|
||||
): Array<string | undefined> {
|
||||
function effectiveColumns(sourceColumns: Array<string | undefined> | undefined, columns: string[]): Array<string | undefined> {
|
||||
if (!sourceColumns || sourceColumns.length !== columns.length) return columns;
|
||||
return sourceColumns;
|
||||
}
|
||||
|
||||
@@ -1,16 +1,5 @@
|
||||
import { ref, computed, type ComputedRef, type Ref } from "vue";
|
||||
import {
|
||||
allCellsSelectionRange,
|
||||
extractColumnsSelection,
|
||||
extractSelection,
|
||||
isCellInSelection,
|
||||
normalizeSelectionRange,
|
||||
normalizeSelectedColumnIndexes,
|
||||
rowSelectionRange,
|
||||
type CellPosition,
|
||||
type CellSelectionRange,
|
||||
type SelectionData,
|
||||
} from "@/lib/gridSelection";
|
||||
import { allCellsSelectionRange, extractColumnsSelection, extractSelection, isCellInSelection, normalizeSelectionRange, normalizeSelectedColumnIndexes, rowSelectionRange, type CellPosition, type CellSelectionRange, type SelectionData } from "@/lib/gridSelection";
|
||||
|
||||
type CellValue = string | number | boolean | null;
|
||||
|
||||
@@ -101,9 +90,7 @@ export function useDataGridSelection(options: UseDataGridSelectionOptions) {
|
||||
}
|
||||
|
||||
function selectColumns(startCol: number, endCol: number, options?: { merge?: boolean }) {
|
||||
const normalizedColumns = normalizeSelectedColumnIndexes(
|
||||
Array.from({ length: Math.abs(endCol - startCol) + 1 }, (_, index) => Math.min(startCol, endCol) + index),
|
||||
);
|
||||
const normalizedColumns = normalizeSelectedColumnIndexes(Array.from({ length: Math.abs(endCol - startCol) + 1 }, (_, index) => Math.min(startCol, endCol) + index));
|
||||
if (normalizedColumns.length === 0 || displayItems.value.length <= 0) return;
|
||||
clearRowSelection();
|
||||
selectionAnchor.value = null;
|
||||
@@ -240,8 +227,7 @@ export function useDataGridSelection(options: UseDataGridSelectionOptions) {
|
||||
}
|
||||
|
||||
function cellIsSelected(rowIndex: number, colIndex: number): boolean {
|
||||
if (hasColumnSelection.value)
|
||||
return rowIndex >= 0 && rowIndex < displayItems.value.length && selectedColumnIndexes.value.has(colIndex);
|
||||
if (hasColumnSelection.value) return rowIndex >= 0 && rowIndex < displayItems.value.length && selectedColumnIndexes.value.has(colIndex);
|
||||
return isCellInSelection(rowIndex, colIndex, selectedRange.value);
|
||||
}
|
||||
|
||||
@@ -249,12 +235,7 @@ export function useDataGridSelection(options: UseDataGridSelectionOptions) {
|
||||
if (hasColumnSelection.value) return selectedColumnIndexes.value.has(colIndex);
|
||||
const range = selectedRange.value;
|
||||
if (!range) return false;
|
||||
return (
|
||||
range.startCol <= colIndex &&
|
||||
range.endCol >= colIndex &&
|
||||
range.startRow === 0 &&
|
||||
range.endRow >= displayItems.value.length - 1
|
||||
);
|
||||
return range.startCol <= colIndex && range.endCol >= colIndex && range.startRow === 0 && range.endRow >= displayItems.value.length - 1;
|
||||
}
|
||||
|
||||
function selectedRangeStart(): CellPosition | null {
|
||||
|
||||
@@ -5,10 +5,7 @@ import { usesTreeSchemaMode } from "@/lib/databaseCapabilities";
|
||||
import type { ConnectionConfig } from "@/types/database";
|
||||
import * as api from "@/lib/api";
|
||||
|
||||
export function databaseOptionsForConnection(
|
||||
databaseNames: string[],
|
||||
connection: Pick<ConnectionConfig, "db_type" | "visible_databases"> | undefined,
|
||||
): string[] {
|
||||
export function databaseOptionsForConnection(databaseNames: string[], connection: Pick<ConnectionConfig, "db_type" | "visible_databases"> | undefined): string[] {
|
||||
const names = filterDatabaseNamesForConnection(databaseNames, connection);
|
||||
if (names.length === 0 && usesTreeSchemaMode(connection?.db_type)) return [""];
|
||||
return names;
|
||||
@@ -34,10 +31,7 @@ export function useDatabaseOptions() {
|
||||
connection,
|
||||
);
|
||||
} else if (connection.db_type === "mongodb") {
|
||||
databaseOptions.value[connectionId] = filterDatabaseNamesForConnection(
|
||||
await api.mongoListDatabases(connectionId),
|
||||
connection,
|
||||
);
|
||||
databaseOptions.value[connectionId] = filterDatabaseNamesForConnection(await api.mongoListDatabases(connectionId), connection);
|
||||
} else {
|
||||
const dbs = await api.listDatabases(connectionId);
|
||||
databaseOptions.value[connectionId] = databaseOptionsForConnection(
|
||||
|
||||
@@ -200,8 +200,7 @@ export function useDialogSources() {
|
||||
showConfigPassphraseDialog.value = false;
|
||||
toast(t("configExport.exportSuccess"), 2000);
|
||||
} catch (e: any) {
|
||||
configPassphraseError.value =
|
||||
e?.message === "crypto_unavailable" ? t("configExport.cryptoUnavailable") : e?.message || String(e);
|
||||
configPassphraseError.value = e?.message === "crypto_unavailable" ? t("configExport.cryptoUnavailable") : e?.message || String(e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -253,12 +252,7 @@ export function useDialogSources() {
|
||||
showImportLayoutConfirm.value = true;
|
||||
}
|
||||
} catch (e: any) {
|
||||
configPassphraseError.value =
|
||||
e?.message === "wrong_passphrase"
|
||||
? t("configExport.wrongPassphrase")
|
||||
: e?.message === "crypto_unavailable"
|
||||
? t("configExport.cryptoUnavailable")
|
||||
: e?.message || String(e);
|
||||
configPassphraseError.value = e?.message === "wrong_passphrase" ? t("configExport.wrongPassphrase") : e?.message === "crypto_unavailable" ? t("configExport.cryptoUnavailable") : e?.message || String(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,9 +17,7 @@ const taskMap = reactive<Map<string, ExportTask>>(new Map());
|
||||
export function useExportTracker() {
|
||||
const tasks = computed(() => Array.from(taskMap.values()));
|
||||
|
||||
const activeCount = computed(
|
||||
() => tasks.value.filter((t) => t.status === "Running" || t.status === "Writing").length,
|
||||
);
|
||||
const activeCount = computed(() => tasks.value.filter((t) => t.status === "Running" || t.status === "Writing").length);
|
||||
|
||||
const hasActive = computed(() => activeCount.value > 0);
|
||||
|
||||
|
||||
@@ -34,13 +34,7 @@ export function shouldAutoScrollExpandedTreeNode(type: TreeNodeType): boolean {
|
||||
return type !== "connection" && type !== "connection-group";
|
||||
}
|
||||
|
||||
export function scrollTopForExpandedTreeNode(options: {
|
||||
expandedIndex: number;
|
||||
insertedRowCount: number;
|
||||
currentScrollTop: number;
|
||||
viewportHeight: number;
|
||||
rowHeight?: number;
|
||||
}): number {
|
||||
export function scrollTopForExpandedTreeNode(options: { expandedIndex: number; insertedRowCount: number; currentScrollTop: number; viewportHeight: number; rowHeight?: number }): number {
|
||||
const rowHeight = options.rowHeight ?? SIDEBAR_TREE_ROW_HEIGHT;
|
||||
if (options.expandedIndex < 0 || options.insertedRowCount <= 0 || options.viewportHeight <= 0) {
|
||||
return options.currentScrollTop;
|
||||
|
||||
@@ -26,9 +26,7 @@ async function openTableTarget(target: NavigationTarget) {
|
||||
const tabTitle = target.schema ? `${target.schema}.${target.tableName}` : target.tableName;
|
||||
const tabId = (() => {
|
||||
if (settingsStore.editorSettings.reuseDataTab) {
|
||||
const existing = queryStore.tabs.find(
|
||||
(tab) => tab.mode === "data" && tab.connectionId === target.connectionId && tab.database === target.database,
|
||||
);
|
||||
const existing = queryStore.tabs.find((tab) => tab.mode === "data" && tab.connectionId === target.connectionId && tab.database === target.database);
|
||||
if (existing) {
|
||||
existing.title = tabTitle;
|
||||
existing.schema = target.schema;
|
||||
@@ -110,17 +108,13 @@ async function openTableTarget(target: NavigationTarget) {
|
||||
}
|
||||
}
|
||||
if (dataResult.status === "rejected") throw dataResult.reason;
|
||||
if (columnsResult.status === "rejected")
|
||||
console.error("[DBX] ERROR fetching table metadata:", columnsResult.reason);
|
||||
if (columnsResult.status === "rejected") console.error("[DBX] ERROR fetching table metadata:", columnsResult.reason);
|
||||
} catch (e: any) {
|
||||
queryStore.setErrorResult(tabId, e);
|
||||
}
|
||||
}
|
||||
|
||||
export function useNavigationTargets(dialogs: {
|
||||
showFieldLineageDialog: { value: boolean };
|
||||
showDatabaseSearchDialog: { value: boolean };
|
||||
}) {
|
||||
export function useNavigationTargets(dialogs: { showFieldLineageDialog: { value: boolean }; showDatabaseSearchDialog: { value: boolean } }) {
|
||||
const connectionStore = useConnectionStore();
|
||||
const queryStore = useQueryStore();
|
||||
|
||||
@@ -134,40 +128,20 @@ export function useNavigationTargets(dialogs: {
|
||||
await openTableTarget(target);
|
||||
}
|
||||
|
||||
async function onStructureEditorSaved(
|
||||
reloadData: () => Promise<void>,
|
||||
toast: (msg: string, duration?: number) => void,
|
||||
context: { connectionId: string; database: string; schema?: string; tableName: string },
|
||||
commentChanged?: boolean,
|
||||
) {
|
||||
async function onStructureEditorSaved(reloadData: () => Promise<void>, toast: (msg: string, duration?: number) => void, context: { connectionId: string; database: string; schema?: string; tableName: string }, commentChanged?: boolean) {
|
||||
if (!context.tableName) {
|
||||
try {
|
||||
await connectionStore.refreshObjectListTreeNode(
|
||||
context.connectionId,
|
||||
context.database,
|
||||
context.schema || undefined,
|
||||
);
|
||||
await connectionStore.refreshObjectListTreeNode(context.connectionId, context.database, context.schema || undefined);
|
||||
} catch {}
|
||||
return;
|
||||
}
|
||||
if (commentChanged) {
|
||||
try {
|
||||
await connectionStore.refreshObjectListTreeNode(
|
||||
context.connectionId,
|
||||
context.database,
|
||||
context.schema || undefined,
|
||||
);
|
||||
await connectionStore.refreshObjectListTreeNode(context.connectionId, context.database, context.schema || undefined);
|
||||
} catch {}
|
||||
}
|
||||
queryStore.invalidateTableStructure(context.connectionId, context.database, context.schema, context.tableName);
|
||||
const matchingDataTabs = queryStore.tabs.filter(
|
||||
(tab) =>
|
||||
tab.mode === "data" &&
|
||||
tab.connectionId === context.connectionId &&
|
||||
tab.database === context.database &&
|
||||
tab.tableMeta?.tableName === context.tableName &&
|
||||
(tab.tableMeta.schema || "") === (context.schema || ""),
|
||||
);
|
||||
const matchingDataTabs = queryStore.tabs.filter((tab) => tab.mode === "data" && tab.connectionId === context.connectionId && tab.database === context.database && tab.tableMeta?.tableName === context.tableName && (tab.tableMeta.schema || "") === (context.schema || ""));
|
||||
for (const tab of matchingDataTabs) {
|
||||
try {
|
||||
const connection = connectionStore.getConfig(tab.connectionId);
|
||||
|
||||
@@ -32,13 +32,7 @@ function primarySqlOperation(sql: string): string {
|
||||
return statement?.match(/^([a-z]+)/i)?.[1]?.toUpperCase() || "SQL";
|
||||
}
|
||||
|
||||
export function useSqlExecution(deps: {
|
||||
activeTab: ComputedRef<QueryTab | undefined>;
|
||||
activeConnection: ComputedRef<ConnectionConfig | undefined>;
|
||||
executableSql: ComputedRef<string>;
|
||||
resolveExecutableSql?: () => Promise<string>;
|
||||
activeOutputView: Ref<"result" | "summary" | "explain" | "chart">;
|
||||
}) {
|
||||
export function useSqlExecution(deps: { activeTab: ComputedRef<QueryTab | undefined>; activeConnection: ComputedRef<ConnectionConfig | undefined>; executableSql: ComputedRef<string>; resolveExecutableSql?: () => Promise<string>; activeOutputView: Ref<"result" | "summary" | "explain" | "chart"> }) {
|
||||
const { t } = useI18n();
|
||||
const queryStore = useQueryStore();
|
||||
const historyStore = useHistoryStore();
|
||||
|
||||
@@ -68,10 +68,7 @@ export function useTabScroll(tabsContainerRef: Ref<HTMLElement | null>) {
|
||||
|
||||
const thumbWidthPx = dragState.trackRect.width * (scrollThumbWidthPercent.value / 100);
|
||||
const maxThumbLeftPx = Math.max(1, dragState.trackRect.width - thumbWidthPx);
|
||||
const thumbLeftPx = Math.min(
|
||||
maxThumbLeftPx,
|
||||
Math.max(0, clientX - dragState.trackRect.left - dragState.thumbOffsetPx),
|
||||
);
|
||||
const thumbLeftPx = Math.min(maxThumbLeftPx, Math.max(0, clientX - dragState.trackRect.left - dragState.thumbOffsetPx));
|
||||
el.scrollLeft = (thumbLeftPx / maxThumbLeftPx) * maxScrollLeft;
|
||||
updateScrollButtons();
|
||||
}
|
||||
|
||||
@@ -2,12 +2,7 @@ import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { useQueryStore } from "@/stores/queryStore";
|
||||
import type { NavigationTarget } from "@/composables/useNavigationTargets";
|
||||
|
||||
export function useTauriEvents(deps: {
|
||||
openTableTarget: (target: NavigationTarget) => Promise<void>;
|
||||
openSqlFilePath: (path: string) => Promise<void>;
|
||||
openDbFilePath: (path: string) => Promise<void>;
|
||||
openConnectionDeepLink: (url: string) => Promise<void>;
|
||||
}) {
|
||||
export function useTauriEvents(deps: { openTableTarget: (target: NavigationTarget) => Promise<void>; openSqlFilePath: (path: string) => Promise<void>; openDbFilePath: (path: string) => Promise<void>; openConnectionDeepLink: (url: string) => Promise<void> }) {
|
||||
const connectionStore = useConnectionStore();
|
||||
const queryStore = useQueryStore();
|
||||
const unlistenHandles: Array<() => void> = [];
|
||||
@@ -23,29 +18,26 @@ export function useTauriEvents(deps: {
|
||||
function setupTauriListeners() {
|
||||
import("@tauri-apps/api/event")
|
||||
.then(({ listen }) => {
|
||||
listen<{ connection_id: string; database: string; schema?: string; table: string }>(
|
||||
"mcp-open-table",
|
||||
async (event) => {
|
||||
try {
|
||||
const { connection_id, database, schema, table } = event.payload;
|
||||
if (!connectionStore.connections.length) await connectionStore.initFromDisk();
|
||||
const config = connectionStore.getConfig(connection_id);
|
||||
if (!config) return;
|
||||
connectionStore.activeConnectionId = connection_id;
|
||||
await connectionStore.ensureConnected(connection_id);
|
||||
if (config.db_type === "redis") {
|
||||
queryStore.createTab(connection_id, database || "0", `db${database || "0"}`, "redis");
|
||||
} else if (config.db_type === "mongodb") {
|
||||
queryStore.createTab(connection_id, database, table, "mongo");
|
||||
} else {
|
||||
deps.openTableTarget({ connectionId: connection_id, database, schema, tableName: table });
|
||||
}
|
||||
focusCurrentWindow();
|
||||
} catch (e) {
|
||||
console.error("[DBX] mcp-open-table error:", e);
|
||||
listen<{ connection_id: string; database: string; schema?: string; table: string }>("mcp-open-table", async (event) => {
|
||||
try {
|
||||
const { connection_id, database, schema, table } = event.payload;
|
||||
if (!connectionStore.connections.length) await connectionStore.initFromDisk();
|
||||
const config = connectionStore.getConfig(connection_id);
|
||||
if (!config) return;
|
||||
connectionStore.activeConnectionId = connection_id;
|
||||
await connectionStore.ensureConnected(connection_id);
|
||||
if (config.db_type === "redis") {
|
||||
queryStore.createTab(connection_id, database || "0", `db${database || "0"}`, "redis");
|
||||
} else if (config.db_type === "mongodb") {
|
||||
queryStore.createTab(connection_id, database, table, "mongo");
|
||||
} else {
|
||||
deps.openTableTarget({ connectionId: connection_id, database, schema, tableName: table });
|
||||
}
|
||||
},
|
||||
).then((unlisten) => unlistenHandles.push(unlisten));
|
||||
focusCurrentWindow();
|
||||
} catch (e) {
|
||||
console.error("[DBX] mcp-open-table error:", e);
|
||||
}
|
||||
}).then((unlisten) => unlistenHandles.push(unlisten));
|
||||
|
||||
listen("mcp-reload-connections", async () => {
|
||||
try {
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
import { computed, ref } from "vue";
|
||||
import {
|
||||
APP_THEME_STORAGE_KEY,
|
||||
getTauriThemeForMode,
|
||||
normalizeAppThemeMode,
|
||||
resolveAppThemeAppearance,
|
||||
type AppThemeMode,
|
||||
} from "@/lib/appTheme";
|
||||
import { APP_THEME_STORAGE_KEY, getTauriThemeForMode, normalizeAppThemeMode, resolveAppThemeAppearance, type AppThemeMode } from "@/lib/appTheme";
|
||||
import { safeLocalStorageGet, safeLocalStorageSet } from "@/lib/safeStorage";
|
||||
import { isTauriRuntime } from "@/lib/tauriRuntime";
|
||||
|
||||
|
||||
Reference in new issue
Block a user