feat(export): add SQL INSERT batch or single-row mode

This commit is contained in:
jearhe authored and GitHub committed 2026-09-06 10:27:34 +08:00
1 parent 5d65be03a3
commit ab35a5b1da
29 files changed
+563 -23

No files matched your search

+4 -2
View File
@@ -1,6 +1,7 @@
import type { DatabaseType, QueryResult } from "@/types/database";
import * as api from "@/lib/backend/api";
import { escapeCsvField, type CsvQuoteMode } from "@/lib/export/csvQuoteMode";
import type { SqlInsertMode } from "@/lib/export/sqlInsertMode";
export type ExportCellValue = string | number | boolean | null;
@@ -38,11 +39,12 @@ export interface FormatSqlInsertOptions {
spatialColumns?: QueryResult["spatial_columns"];
spatialValues?: QueryResult["spatial_values"];
rows: ExportCellValue[][];
insertMode?: SqlInsertMode;
}
export function formatSqlInsert(options: FormatSqlInsertOptions): Promise<string> {
export function formatSqlInsert({ insertMode = "batch", ...options }: FormatSqlInsertOptions): Promise<string> {
return api.buildExportSqlInsert({
...options,
batchSize: 1,
batchSize: insertMode === "single" ? 1 : undefined,
});
}
@@ -0,0 +1,32 @@
import { createApp } from "vue";
import SqlInsertModeDialog from "@/components/export/SqlInsertModeDialog.vue";
import i18n from "@/i18n";
export type SqlInsertMode = "batch" | "single";
export const DEFAULT_SQL_INSERT_MODE: SqlInsertMode = "batch";
export function showSqlInsertModeDialog(): Promise<SqlInsertMode | null> {
if (typeof document === "undefined") return Promise.resolve(DEFAULT_SQL_INSERT_MODE);
return new Promise((resolve) => {
const container = document.createElement("div");
document.body.append(container);
let settled = false;
let app: ReturnType<typeof createApp> | null = null;
const finish = (value: SqlInsertMode | null) => {
if (settled) return;
settled = true;
resolve(value);
app?.unmount();
container.remove();
};
app = createApp(SqlInsertModeDialog, {
open: true,
onConfirm: (insertMode: SqlInsertMode) => finish(insertMode),
onCancel: () => finish(null),
});
app.use(i18n);
app.mount(container);
});
}