feat(export): add SQL INSERT batch or single-row mode
This commit is contained in:
1 parent
5d65be03a3
commit
ab35a5b1da
29 files changed
+563
-23
No files matched your search
@@ -9,6 +9,7 @@ import { decodeMeilisearchDocumentPage, decodeMeilisearchSearchResult, type Meil
|
||||
import type { XuguTablespaceInfo } from "@/types/database";
|
||||
import type { CreatedKey, EnqueuedTaskSummary, KeyCreateInput, KeyListItem, KeyPage, KeyUpdateInput, MeilisearchSystemOverview, MeilisearchTask, TaskListInput, TaskPage, TaskSelector } from "@/types/meilisearchManagement";
|
||||
import type { CsvQuoteMode } from "@/lib/export/csvQuoteMode";
|
||||
import type { SqlInsertMode } from "@/lib/export/sqlInsertMode";
|
||||
|
||||
/** Normalize Tauri rejections once at the public backend boundary. */
|
||||
async function invokeBackend<T>(command: string, args?: Record<string, unknown>): Promise<T> {
|
||||
@@ -4843,6 +4844,7 @@ export interface TableExportRequest {
|
||||
tableName: string;
|
||||
filePath: string;
|
||||
format: "csv" | "xlsx" | "json" | "markdown" | "sql" | "txt";
|
||||
insertMode?: SqlInsertMode;
|
||||
csvQuoteMode?: CsvQuoteMode;
|
||||
columns?: string[];
|
||||
columnTypes?: Array<string | null | undefined>;
|
||||
@@ -4892,6 +4894,7 @@ export interface QueryResultExportRequest {
|
||||
useAgentCursor: boolean;
|
||||
filePath: string;
|
||||
format: "csv" | "xlsx" | "txt" | "sql";
|
||||
insertMode?: SqlInsertMode;
|
||||
csvQuoteMode?: CsvQuoteMode;
|
||||
includeSqlSheet?: boolean;
|
||||
pageSize: number;
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user