-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream_array_join.js
69 lines (54 loc) · 1.35 KB
/
stream_array_join.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
63
64
65
66
67
68
console.time("exchange");
var mysql = require('mysql');
var arango = require('arango');
var json_transform = require('./json_transform_stream');
var docs = [];
function importArango(json, cb) {
if (typeof json != "undefined")
docs.push(json);
// buffer size makes very little difference in speed,
// 31s @100, 29s @2000,
// memory consumption is a bit higher with larger buffer
if (docs.length >= 10000 || typeof json == "undefined") {
stream.pause();
db.import.importJSONData(
"fa_stammdaten_stream_array_join",
docs.join(""),
{
createCollection: true,
waitForSync: false
},
function (err, res) {
if (err) {
console.log(err);
}
docs = [];
stream.resume();
if (typeof cb == "function") cb();
}
);
}
}
var encoder = new json_transform.stream();
encoder
.on('readable', function () {
importArango(encoder.read());
})
.on('end', function () {
// write rest
importArango(undefined, function() {
console.timeEnd("exchange");
process.exit();
});
});
var connection = mysql.createConnection({
host: 'localhost',
user: 'root',
password: ''
});
var db = arango.Connection("http://localhost:8529/amtub");
console.log("Connecting to MySQL");
connection.connect();
var query = connection.query('SELECT * FROM _import_mysql.fa_stammdaten');
var stream = query.stream();
stream.pipe(encoder);