0

我正在从 mysql 数据库中导出描述字段:

SELECT REPLACE(description, char(13), '\\n') 
FROM table u  INTO OUTFILE '/var/lib/mysql-files/u.csv' 
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"' 
LINES TERMINATED BY '\n';

然后在 nodejs 中,我使用 csv-parse 处理文件(在处理异步时必须使用这个文件):

const parse       = promisify(require('csv-parse'));
const records = await parse(fileContents, { delimiter: ',', columns: true, skip_empty_lines: true, record_delimiter: "\n" });

这是一个示例文本:

Married, mad scientist and tennisman from Germany. I might not be able
to spell the word "ubuntu" without spellcheck software, but be sure I
know the meaning.

然而,解析器弄错了,将其拆分为 3 个字段:

'"Married, mad scientist and tennisman from Germany. I might not be
able to spell the word \\"ubuntu\\" without spellcheck software', 
'but be sure I know the meaning."',  
'\\N'

第 3 个字段来自 mysql,由于某种原因,该文件以 \N 结尾而不是 \n 保存。我可以通过 sed 以及行尾逗号来删除它,但如果我的查询可以避免这种情况,我总是很感激一些提示。

然而,对于将正文分成 2 个字段,我感到很困惑。我尝试在解析中删除分隔符参数,但同样的问题。我试着放松:真的,一样。

知道我在做什么错吗?

4

0 回答 0