mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-28 08:08:02 +00:00
29 lines
889 B
TypeScript
29 lines
889 B
TypeScript
import type { DatabaseType } from "@/types/database";
|
|
import * as api from "@/lib/api";
|
|
|
|
export type ExportCellValue = string | number | boolean | null;
|
|
|
|
export function formatCsv(columns: string[], rows: ExportCellValue[][]): string {
|
|
const esc = (v: string) => `"${v.replace(/"/g, '""')}"`;
|
|
const header = columns.map(esc).join(",");
|
|
const body = rows.map((row) => row.map((c) => esc(c === null ? "" : String(c))).join(",")).join("\n");
|
|
return `${header}\n${body}`;
|
|
}
|
|
|
|
export interface FormatSqlInsertOptions {
|
|
databaseType?: DatabaseType;
|
|
schema?: string;
|
|
tableName?: string;
|
|
qualifiedTableName?: string;
|
|
columns: string[];
|
|
columnTypes?: Array<string | null | undefined>;
|
|
rows: ExportCellValue[][];
|
|
}
|
|
|
|
export function formatSqlInsert(options: FormatSqlInsertOptions): Promise<string> {
|
|
return api.buildExportSqlInsert({
|
|
...options,
|
|
batchSize: 1,
|
|
});
|
|
}
|