feat(import): add SQL script import with dialect-aware parsing
This commit is contained in:
1 parent
ab4e747bf9
commit
dfd4d3b7ff
15 files changed
+809
-12
No files matched your search
@@ -86,6 +86,7 @@ export interface TableImportParseSettings {
|
||||
emptyStringAsNull: boolean;
|
||||
sheetName?: string;
|
||||
jsonShape: TableImportJsonShape;
|
||||
databaseType?: DatabaseType | null;
|
||||
}
|
||||
|
||||
export function defaultTableImportEmptyStringAsNull(format: TableImportSourceFormat): boolean {
|
||||
@@ -94,9 +95,11 @@ export function defaultTableImportEmptyStringAsNull(format: TableImportSourceFor
|
||||
|
||||
export function buildTableImportParseOptions(settings: TableImportParseSettings): TableImportParseOptions {
|
||||
const isDelimited = settings.format === "csv" || settings.format === "tsv" || settings.format === "delimited";
|
||||
// SQL 脚本与分隔文本一样是纯文本源,需要传递编码供后端解码(支持 GBK 等常见转储编码)
|
||||
const isTextSource = isDelimited || settings.format === "sql";
|
||||
return {
|
||||
delimiter: settings.format === "tsv" ? "\\t" : settings.format === "csv" ? "," : settings.delimiter,
|
||||
encoding: isDelimited ? settings.textEncoding : null,
|
||||
encoding: isTextSource ? settings.textEncoding : null,
|
||||
titleRow: settings.titleRow,
|
||||
dataStartRow: settings.dataStartRow,
|
||||
lastDataRow: settings.lastDataRow,
|
||||
@@ -104,6 +107,8 @@ export function buildTableImportParseOptions(settings: TableImportParseSettings)
|
||||
emptyStringAsNull: settings.emptyStringAsNull,
|
||||
sheetName: settings.format === "excel" ? settings.sheetName || null : null,
|
||||
jsonShape: settings.format === "json" ? settings.jsonShape : null,
|
||||
// SQL 脚本需要按源方言解析字符串转义与标识符大小写(取目标连接的数据库类型)
|
||||
sqlDialect: settings.format === "sql" ? (settings.databaseType ?? null) : null,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user