-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream_str_concat.js
71 lines (58 loc) · 1.22 KB
/
stream_str_concat.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
69
70
71
console.time("exchange");
var mysql = require('mysql');
var arango = require('arango');
var json_transform = require('./json_transform_stream');
var str = "";
var c = 0;
function importArango(json, cb) {
if (json) {
str += json;
c++;
}
//if (c >= 1000 || !json) {
// buffer approx. 5 MB
if (str.length > 5000000 || !json) {
c = 0;
stream.pause();
db.import.importJSONData(
"fa_stammdaten_stream_str_concat",
str,
{
createCollection: true,
waitForSync: false
},
function (err, res) {
if (err) {
console.log(err);
}
str = "";
stream.resume();
cb();
}
);
}
}
function noop(){}
var encoder = new json_transform.stream();
encoder
.on('readable', function() {
importArango(encoder.read(), noop);
})
.on('end', function() {
// write rest
importArango("", 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);