feat(export): add streaming TXT data export

This commit is contained in:
Abeautifulsnow authored and GitHub committed 2026-07-13 20:44:57 +08:00
1 parent 99b84cbc92
commit 78b3bb1ba1
17 files changed
+471 -81

No files matched your search

+2 -2
View File
@@ -2234,7 +2234,7 @@ export interface TableExportRequest {
schema?: string;
tableName: string;
filePath: string;
format: "csv" | "xlsx" | "json" | "markdown" | "sql";
format: "csv" | "xlsx" | "json" | "markdown" | "sql" | "txt";
columns?: string[];
columnTypes?: Array<string | null | undefined>;
primaryKeys?: string[];
@@ -2275,7 +2275,7 @@ export interface QueryResultExportRequest {
databaseType: DatabaseType;
useAgentCursor: boolean;
filePath: string;
format: "csv" | "xlsx";
format: "csv" | "xlsx" | "txt";
pageSize: number;
rowLimit?: number | null;
totalRows?: number | null;
@@ -10,6 +10,23 @@ export function formatCsv(columns: string[], rows: ExportCellValue[][]): string
return `${header}\n${body}`;
}
// Tab-separated values with a header row, mirroring Navicat's "Text File (*.txt)"
// export: fields are joined by a tab, NULL becomes empty, and a field is only
// wrapped in double quotes (with " doubled) when it contains a tab, newline,
// or quote - i.e. the minimum needed to round-trip the value.
export function formatTsv(columns: string[], rows: ExportCellValue[][]): string {
const esc = (value: ExportCellValue) => {
const text = value === null ? "" : String(value);
if (text.includes("\t") || text.includes("\n") || text.includes("\r") || text.includes('"')) {
return `"${text.replace(/"/g, '""')}"`;
}
return text;
};
const header = columns.map(esc).join("\t");
const body = rows.map((row) => row.map(esc).join("\t")).join("\n");
return `${header}\n${body}`;
}
export interface FormatSqlInsertOptions {
databaseType?: DatabaseType;
schema?: string;