本文介绍了在 MySQL 中使用 Streams 和 Node的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按照 使用 Streams2 处理结果 上的示例,我'正在尝试将结果从 MySQL 流式传输到 node.js 中的 stdout.
Following the example on Piping results with Streams2, I'm trying to stream results from MySQL to stdout in node.js.
代码如下:
connection.query('SELECT * FROM table')
.stream()
.pipe(process.stdout);
我收到此错误:TypeError: invalid data
推荐答案
说明
来自这个 github issue 项目:
.stream()
以objectMode"返回流.你不能把它传送到标准输出或网络套接字,因为数据"事件将行作为有效负载,而不是缓冲区块
修复
您可以使用 csv-stringify
解决此问题模块.
Fix
You can fix this using the csv-stringify
module.
var stringify = require('csv-stringify');
var stringifier = stringify();
connection.query('SELECT * FROM table')
.stream()
.pipe(stringifier).pipe(process.stdout);
注意 .pipe(process.stdout)
这篇关于在 MySQL 中使用 Streams 和 Node的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!