fix(export): mark NULL as \N in CSV and TSV exports
This commit is contained in:
49 files changed
+1056
-130
No files matched your search
+21
-3
@@ -2,7 +2,9 @@ import { strict as assert } from "node:assert";
|
||||
import { test } from "vitest";
|
||||
import { formatCsv } from "../../apps/desktop/src/lib/export/exportFormats.ts";
|
||||
|
||||
test("formatCsv writes database null as an empty cell and preserves literal NULL", () => {
|
||||
// NULL 必须写成独立字面量、空字符串才写成空字段,否则导出再导入时 '' 会被还原成
|
||||
// NULL,写回 NOT NULL DEFAULT '' 的列就会报「不允许为 null」。
|
||||
test("formatCsv writes database null as the shared NULL literal and keeps empty strings empty", () => {
|
||||
assert.equal(
|
||||
formatCsv(
|
||||
["id", "note"],
|
||||
@@ -12,7 +14,22 @@ test("formatCsv writes database null as an empty cell and preserves literal NULL
|
||||
[3, "NULL"],
|
||||
],
|
||||
),
|
||||
'"id","note"\n"1",\n"2",""\n"3","NULL"',
|
||||
'"id","note"\n"1",\\N\n"2",""\n"3","NULL"',
|
||||
);
|
||||
});
|
||||
|
||||
test("formatCsv keeps the legacy empty-cell NULL when the literal is explicitly disabled", () => {
|
||||
assert.equal(
|
||||
formatCsv(
|
||||
["id", "note"],
|
||||
[
|
||||
[1, null],
|
||||
[2, ""],
|
||||
],
|
||||
"all",
|
||||
"",
|
||||
),
|
||||
'"id","note"\n"1",\n"2",""',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -23,9 +40,10 @@ test("formatCsv only quotes fields with CSV special characters in necessary mode
|
||||
[
|
||||
[2085252644, "延庆县", "plain"],
|
||||
[2085252645, "门头沟区", 'line 1\n"line 2"'],
|
||||
[2085252646, "昌平区", null],
|
||||
],
|
||||
"necessary",
|
||||
),
|
||||
'id,"district,name",note\n2085252644,延庆县,plain\n2085252645,门头沟区,"line 1\n""line 2"""',
|
||||
'id,"district,name",note\n2085252644,延庆县,plain\n2085252645,门头沟区,"line 1\n""line 2"""\n2085252646,昌平区,\\N',
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user