-
Notifications
You must be signed in to change notification settings - Fork 0
/
test1.js
62 lines (55 loc) · 1.07 KB
/
test1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"use strict"
const through = require('through2');
const DbRowParser = require("./DbRowParser");
const DbRowParserStream = require("./DbRowParserStream");
let hobby = new DbRowParser({
key: "hobbyId",
properties: ["hobbyId", "hobbyName"]
});
let person = new DbRowParser({
key: "id",
properties: ["id", "name", {
hobbies: [hobby]
}]
});
let stream = new DbRowParserStream({
rowParser: person
});
let t = through.obj(
function(obj, encoding, cb) {
this.push(JSON.stringify(obj) + "\n");
cb();
});
stream
.pipe(t)
.pipe(process.stdout);
let data = [{
id: 1,
name: "Pascal",
hobbyId: 10,
hobbyName: "Fly Fishing"
}, {
id: 1,
name: "Pascal",
hobbyId: 11,
hobbyName: "Cross Country Skiing"
}, {
id: 2,
name: "Patricia",
hobbyId: 20,
hobbyName: "Movie"
}, {
id: 2,
name: "Patricia",
hobbyId: 21,
hobbyName: "Puzzle"
}, {
id: 3,
name: "Mackenzie",
hobbyId: 30,
hobbyName: "Reading"
}];
data.forEach((d) => {
stream.write(d);
});
stream.end(null);