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

@@ -20,6 +20,7 @@ import { Input } from "@/components/ui/input";
import { Download, Square, CheckSquare, Search, X, Loader2, Wrench } from "@lucide/vue";
import { formatDataTransferDuration, useExportTracker } from "@/composables/useExportTracker";
import { isQueryTimeoutErrorMessage } from "@/lib/sql/queryError";
import type { SqlInsertDialect } from "@/lib/export/sqlInsertMode";
const { t } = useI18n();
const { toast } = useToast();
@@ -64,6 +65,7 @@ const POSTGRES_ALL_SCHEMAS = "__DBX_ALL_SCHEMAS__";
// Options
const includeStructure = ref(true);
const includeData = ref(true);
const insertDialect = ref<SqlInsertDialect>("source");
const includeObjects = ref(true);
const includeCreateDatabase = ref(false);
const dropTableIfExists = ref(false);
@@ -396,6 +398,7 @@ async function startExport() {
selectedTables: !isPostgresAllSchemas.value && (includeStructure.value || includeData.value) ? buildSelectedTablesPayload(tables.value, selectedTables.value) : undefined,
includeStructure: includeStructure.value,
includeData: includeData.value,
insertDialect: insertDialect.value,
includeObjects: includeObjects.value,
includeCreateDatabase: includeCreateDatabase.value,
dropTableIfExists: dropTableIfExists.value,
@@ -538,6 +541,7 @@ async function startAllDatabasesExport() {
filePath,
includeStructure: includeStructure.value,
includeData: includeData.value,
insertDialect: insertDialect.value,
includeObjects: includeObjects.value,
includeCreateDatabase: includeCreateDatabase.value,
dropTableIfExists: dropTableIfExists.value,
@@ -659,6 +663,7 @@ function resetState() {
databaseFilter.value = "";
includeStructure.value = true;
includeData.value = true;
insertDialect.value = "source";
includeObjects.value = true;
includeCreateDatabase.value = false;
dropTableIfExists.value = false;
@@ -947,6 +952,16 @@ watch(
<Square v-else class="w-3.5 h-3.5 text-muted-foreground/40 shrink-0" />
{{ t("databaseExport.includeData") }}
</div>
<div class="space-y-1">
<button type="button" class="flex items-center gap-2 text-left text-xs" :class="includeData ? 'cursor-pointer' : 'cursor-not-allowed text-muted-foreground/50'" :disabled="!includeData" @click="insertDialect = insertDialect === 'standard' ? 'source' : 'standard'">
<CheckSquare v-if="includeData && insertDialect === 'standard'" class="w-3.5 h-3.5 text-primary shrink-0" />
<Square v-else class="w-3.5 h-3.5 text-muted-foreground/40 shrink-0" />
{{ t("databaseExport.standardSqlInsert") }}
</button>
<p class="pl-5 text-[11px] text-muted-foreground">
{{ t("databaseExport.standardSqlInsertDescription") }}
</p>
</div>
<div class="flex items-center gap-2 cursor-pointer text-xs" @click="includeObjects = !includeObjects">
<CheckSquare v-if="includeObjects" class="w-3.5 h-3.5 text-primary shrink-0" />
<Square v-else class="w-3.5 h-3.5 text-muted-foreground/40 shrink-0" />
@@ -101,7 +101,7 @@ import { buildRenameObjectSql, supportsObjectRename } from "@/lib/table/objectRe
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
import { generateDatabaseExportId } from "@/lib/export/databaseExport";
import { buildXlsxHeaderOverrides, hasXlsxHeaderComments, type XlsxExportOptions, type XlsxHeaderMode } from "@/lib/export/xlsxHeader";
import { showSqlInsertModeDialog, type SqlInsertMode } from "@/lib/export/sqlInsertMode";
import { showSqlInsertModeDialog, type SqlInsertDialect, type SqlInsertMode } from "@/lib/export/sqlInsertMode";
import { copyToClipboard, eventTargetAllowsAppClipboardShortcut } from "@/lib/common/clipboard";
import {
defaultPasteTableMode,
@@ -2321,14 +2321,14 @@ async function exportDataLegacy(row: ObjectBrowserRow, format: "json") {
}
}
async function exportData(row: ObjectBrowserRow, format: "csv" | "json" | "sql") {
async function exportData(row: ObjectBrowserRow, format: "csv" | "json" | "sql", insertDialect: SqlInsertDialect = "source") {
if (format === "json") {
await exportDataLegacy(row, format);
return;
}
const sqlExportOptions = format === "sql" ? await showSqlInsertModeDialog({ allowSplit: true }) : undefined;
if (format === "sql" && sqlExportOptions === null) return;
await exportTableData(row, format, undefined, "name", true, sqlExportOptions?.insertMode ?? "batch", sqlExportOptions?.splitMaxMb);
await exportTableData(row, format, undefined, "name", true, sqlExportOptions?.insertMode ?? "batch", sqlExportOptions?.splitMaxMb, insertDialect);
}
function showObjectBrowserXlsxHeaderDialog(hasComments: boolean): Promise<XlsxExportOptions | null> {
@@ -2371,7 +2371,7 @@ async function exportDataXlsx(row: ObjectBrowserRow) {
await exportTableData(row, "xlsx", columnInfos, exportOptions.headerMode, exportOptions.autoFilter);
}
async function exportTableData(row: ObjectBrowserRow, format: "csv" | "xlsx" | "sql", columnInfos?: ColumnInfo[], headerMode: XlsxHeaderMode = "name", autoFilter = true, insertMode: SqlInsertMode = "batch", splitMaxMb?: number) {
async function exportTableData(row: ObjectBrowserRow, format: "csv" | "xlsx" | "sql", columnInfos?: ColumnInfo[], headerMode: XlsxHeaderMode = "name", autoFilter = true, insertMode: SqlInsertMode = "batch", splitMaxMb?: number, insertDialect: SqlInsertDialect = "source") {
const schema = row.schema || selectedSchema.value;
const splitSqlOutput = format === "sql" && splitMaxMb !== undefined;
@@ -2446,7 +2446,7 @@ async function exportTableData(row: ObjectBrowserRow, format: "csv" | "xlsx" | "
tableName: row.name,
filePath,
format,
...(format === "sql" ? { insertMode, splitMaxMb } : {}),
...(format === "sql" ? { insertMode, insertDialect, splitMaxMb } : {}),
csvQuoteMode: settingsStore.editorSettings.csvQuoteMode,
columns,
columnComments: format === "xlsx" ? columnComments : undefined,
@@ -3373,7 +3373,10 @@ function exportDataSubmenu(item: ObjectBrowserRow): ContextMenuItem {
{ label: "CSV", action: () => exportData(item, "csv") },
{ label: "JSON", action: () => exportData(item, "json") },
];
if (!isVictoriaMetrics.value) formats.push({ label: "SQL INSERT", action: () => exportData(item, "sql") });
if (!isVictoriaMetrics.value) {
formats.push({ label: "SQL INSERT", action: () => exportData(item, "sql", "source") });
formats.push({ label: t("contextMenu.standardSqlInsert"), action: () => exportData(item, "sql", "standard") });
}
formats.push({ label: "XLSX", action: () => exportDataXlsx(item) });
return {
label: t("contextMenu.exportData"),
@@ -5492,7 +5492,10 @@ function exportDataSubmenu(includeSqlInsert = true): ContextMenuItem {
{ label: "CSV", action: () => exportData("csv") },
{ label: "JSON", action: () => exportData("json") },
];
if (includeSqlInsert) children.push({ label: "SQL INSERT", action: () => exportData("sql") });
if (includeSqlInsert) {
children.push({ label: "SQL INSERT", action: () => exportData("sql", "source") });
children.push({ label: t("contextMenu.standardSqlInsert"), action: () => exportData("sql", "standard") });
}
children.push({ label: "XLSX", action: () => exportDataXlsx() });
return {
label: count > 1 ? t("contextMenu.exportDataMultiple", { count }) : t("contextMenu.exportData"),