feat(export): add portable standard SQL inserts

Closes #9869
This commit is contained in:
t8y2 committed 2026-09-27 15:56:52 +00:00
1 parent ba3872abef
commit 1d07cb05e0
22 files changed
+384 -83

No files matched your search

@@ -540,4 +540,35 @@ describe("useSidebarTreeExportRuntime", () => {
expect(apiMock.startTableExport).toHaveBeenCalledOnce();
expect(apiMock.startTableExport).toHaveBeenCalledWith(expect.objectContaining({ tableName: "users", filePath: "users.csv" }), expect.any(Function));
});
it.each([
["source", undefined],
["standard", "standard"],
] as const)("serializes the %s SQL INSERT dialect for a table export", async (expectedDialect, requestedDialect) => {
const activeNode = shallowRef({ id: "table-1", type: "table", label: "users", connectionId: "conn-1", database: "db", schema: "dbo", children: [] } as TreeNode);
const connectionStore = {
ensureConnected: vi.fn(),
getConfig: vi.fn(() => ({ db_type: "sqlserver" })),
connectionIdentifierQuote: vi.fn(() => "["),
treeNodes: [],
selectedTreeNodeIds: [],
};
const runtime = useSidebarTreeExportRuntime({
activeNode,
connectionStore: connectionStore as never,
settingsStore: exportSettings() as never,
acceptedSelectionIds: () => null,
});
await runtime.exportData("sql", requestedDialect);
expect(apiMock.startTableExport).toHaveBeenCalledWith(
expect.objectContaining({
format: "sql",
insertDialect: expectedDialect,
identifierQuote: "[",
}),
expect.any(Function),
);
});
});
@@ -32,6 +32,7 @@ import {
structurePreviewDdlStorageType,
} from "@/components/sidebar/sidebarTreeDialogState";
import type { CsvQuoteMode } from "@/lib/export/csvQuoteMode";
import type { SqlInsertDialect } from "@/lib/export/sqlInsertMode";
type StructureCopyFormat = "tsv" | "markdown";
@@ -90,6 +91,7 @@ interface ExportTableDataOptions {
autoFilter?: boolean;
outputDirectory?: string;
suppressDoneToast?: boolean;
insertDialect?: SqlInsertDialect;
}
function joinExportFilePath(directory: string, fileName: string): string {
@@ -434,7 +436,7 @@ export function useSidebarTreeExportRuntime(options: SidebarTreeExportRuntimeOpt
}
async function exportTableData(target: SidebarTableExportTarget, format: "csv" | "xlsx" | "sql", exportOptions: ExportTableDataOptions = {}) {
const { columnInfos, headerMode = "name", autoFilter = true, outputDirectory, suppressDoneToast = false } = exportOptions;
const { columnInfos, headerMode = "name", autoFilter = true, outputDirectory, suppressDoneToast = false, insertDialect = "source" } = exportOptions;
const { connectionId, database } = target;
let task: ExportTask | null = null;
@@ -486,6 +488,7 @@ export function useSidebarTreeExportRuntime(options: SidebarTreeExportRuntimeOpt
tableName: target.tableName,
filePath: outputPath,
format,
...(format === "sql" ? { insertDialect } : {}),
csvQuoteMode: target.csvQuoteMode,
columns: queryColumns,
columnComments,
@@ -566,7 +569,7 @@ export function useSidebarTreeExportRuntime(options: SidebarTreeExportRuntimeOpt
}
}
async function exportData(format: "csv" | "json" | "sql") {
async function exportData(format: "csv" | "json" | "sql", insertDialect: SqlInsertDialect = "source") {
const targets = currentTableExportTargets();
if (!targets.length) return;
@@ -584,7 +587,7 @@ export function useSidebarTreeExportRuntime(options: SidebarTreeExportRuntimeOpt
let exported = 0;
for (const target of targets) {
if (await exportTableData(target, format, { outputDirectory, suppressDoneToast: targets.length > 1 })) exported += 1;
if (await exportTableData(target, format, { outputDirectory, suppressDoneToast: targets.length > 1, insertDialect })) exported += 1;
}
if (targets.length > 1 && exported > 0) toast(t("contextMenu.exportDataMultipleSuccess", { count: exported }));
}