feat(export): split large sql exports into zip parts
This commit is contained in:
1 parent
339c96cc81
commit
16866293a3
30 files changed
+933
-57
No files matched your search
@@ -15,7 +15,7 @@ import { copyToClipboard } from "@/lib/common/clipboard";
|
||||
import { clearDataGridClipboardCopy, rememberDataGridClipboardCopy } from "@/lib/dataGrid/dataGridClipboard";
|
||||
import { buildDataGridCopyInsertStatement, type DataGridCopyInsertMode, type DataGridTableMeta } from "@/lib/dataGrid/dataGridSql";
|
||||
import { formatSqlInsert, formatTsv } from "@/lib/export/exportFormats";
|
||||
import { showSqlInsertModeDialog, type SqlInsertMode } from "@/lib/export/sqlInsertMode";
|
||||
import { showSqlInsertModeDialog, type SqlExportOptions, type SqlInsertMode } from "@/lib/export/sqlInsertMode";
|
||||
import { summarizeExportRows } from "@/lib/export/exportDiagnostics";
|
||||
import { appendDebugLog, appendNativeProcessMemoryLog, getBrowserMemorySnapshot, isDebugLoggingEnabled } from "@/lib/backend/debugLog";
|
||||
import { uuid } from "@/lib/common/utils";
|
||||
@@ -1164,7 +1164,7 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
await exportAllResultsXlsxResult(true);
|
||||
}
|
||||
|
||||
async function exportFullTableDataViaBackend(format: "csv" | "xlsx" | "json" | "markdown" | "sql" | "txt", rowIds?: number[], headerMode: XlsxHeaderMode = "name", autoFilter = true, insertMode?: SqlInsertMode): Promise<boolean> {
|
||||
async function exportFullTableDataViaBackend(format: "csv" | "xlsx" | "json" | "markdown" | "sql" | "txt", rowIds?: number[], headerMode: XlsxHeaderMode = "name", autoFilter = true, sqlExportOptions?: SqlExportOptions): Promise<boolean> {
|
||||
const meta = tableMeta.value;
|
||||
// The backend table exporter currently builds two-part table names. External
|
||||
// Doris/StarRocks catalogs need the data-tab paginator's three-part SQL.
|
||||
@@ -1173,8 +1173,9 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
}
|
||||
|
||||
const fmt = FORMAT_META[format];
|
||||
const extension = fmt?.ext ?? format;
|
||||
const filterName = fmt?.label ?? format.toUpperCase();
|
||||
const splitSqlOutput = format === "sql" && sqlExportOptions?.splitMaxMb !== undefined;
|
||||
const extension = splitSqlOutput ? "zip" : (fmt?.ext ?? format);
|
||||
const filterName = splitSqlOutput ? "ZIP" : (fmt?.label ?? format.toUpperCase());
|
||||
let outputPath = exportFileName(meta.tableName || "export", extension, { preferFallback: true });
|
||||
if (isTauriRuntime()) {
|
||||
const { save } = await import("@tauri-apps/plugin-dialog");
|
||||
@@ -1223,7 +1224,7 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
tableName: meta.tableName,
|
||||
filePath: outputPath,
|
||||
format,
|
||||
...(format === "sql" && insertMode ? { insertMode } : {}),
|
||||
...(format === "sql" && sqlExportOptions ? { insertMode: sqlExportOptions.insertMode, splitMaxMb: sqlExportOptions.splitMaxMb } : {}),
|
||||
csvQuoteMode: editorSettings.csvQuoteMode,
|
||||
columns: columns.value,
|
||||
columnTypes: columnTypes.value,
|
||||
@@ -1409,16 +1410,18 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
},
|
||||
true,
|
||||
);
|
||||
const insertMode = await showSqlInsertModeDialog();
|
||||
if (insertMode === null) {
|
||||
const selectedSqlExportOptions = (await showSqlInsertModeDialog({ allowSplit: rowIds === undefined && context.value === "table-data" })) as SqlExportOptions | SqlInsertMode | null;
|
||||
if (selectedSqlExportOptions === null) {
|
||||
logExportStage("cancelled", { stage: "insert-mode-dialog" });
|
||||
return;
|
||||
}
|
||||
logExportStage("mode-selected", { insertMode });
|
||||
const sqlExportOptions = typeof selectedSqlExportOptions === "string" ? { insertMode: selectedSqlExportOptions } : selectedSqlExportOptions;
|
||||
const insertMode = sqlExportOptions.insertMode;
|
||||
logExportStage("mode-selected", { insertMode, splitMaxMb: sqlExportOptions.splitMaxMb });
|
||||
try {
|
||||
// Step 1: table-data context — existing backend table export
|
||||
logExportStage("backend-export-start");
|
||||
const handledByBackend = await exportFullTableDataViaBackend("sql", rowIds, "name", true, insertMode);
|
||||
const handledByBackend = await exportFullTableDataViaBackend("sql", rowIds, "name", true, sqlExportOptions);
|
||||
logExportStage("backend-export-finished", { handledByBackend });
|
||||
if (handledByBackend) {
|
||||
logExportStage("done", { path: "backend" });
|
||||
@@ -1490,8 +1493,9 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
|
||||
async function exportCurrentPageSql() {
|
||||
await runExclusiveExport(async () => {
|
||||
const insertMode = await showSqlInsertModeDialog();
|
||||
if (insertMode === null) return;
|
||||
const selectedSqlExportOptions = (await showSqlInsertModeDialog()) as SqlExportOptions | SqlInsertMode | null;
|
||||
if (selectedSqlExportOptions === null) return;
|
||||
const insertMode = typeof selectedSqlExportOptions === "string" ? selectedSqlExportOptions : selectedSqlExportOptions.insertMode;
|
||||
try {
|
||||
const result = await resultToExport(undefined, undefined, false, false);
|
||||
const exportData = sqlInsertExportData(result);
|
||||
|
||||
Reference in new issue
Block a user