Skip to content

Commit f919f10

Browse files
author
Sylvestre
authored
Fix chunk (#44)
1 parent 223b956 commit f919f10

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

lib/mssql.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,21 @@ export async function queryStream(req, res, pool) {
101101
new Transform({
102102
objectMode: true,
103103
transform(chunk, encoding, cb) {
104-
const row = chunk.reduce((acc, r, idx) => {
105-
const key = columnNameMap.get(idx);
106-
return {...acc, [key]: r};
107-
}, {});
108-
109-
cb(null, row);
104+
if (Array.isArray(chunk)) {
105+
const row = chunk.reduce((acc, r, idx) => {
106+
const key = columnNameMap.get(idx);
107+
return {...acc, [key]: r};
108+
}, {});
109+
cb(null, row);
110+
} else {
111+
cb(new Error("row has unexpected format"), chunk);
112+
}
110113
},
111114
})
112115
)
113116
.pipe(JSONStream.stringify("", "\n", "\n"))
114117
.pipe(res);
118+
115119
stream.on("done", () => {
116120
resolve();
117121
});

0 commit comments

Comments
 (0)