-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
57 lines (51 loc) · 1.05 KB
/
index.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
"use strict";
const filename='./input/sample-100.osm';
const batchSize = 1000;
const connectionstr = 'mongodb://localhost:27017/testdb';
const { db } = require('./db');
const dbConfig={
connectionstr
}
const dbcon = db(dbConfig)
const streamConfig = {
dbcon,
batchSize,
inputfile:filename
}
const {
inputStream,
batchStream,
transformStream,
groupStream,
dbStream,
saxStream,
progressStream
} = require('./streams')(streamConfig)
function parse(dbcon){
batchStream.pipe(progressStream).pipe(process.stdout);
return inputStream
.pipe(saxStream)
.pipe(transformStream)
.pipe(batchStream)
.pipe(groupStream)
.pipe(dbStream)
}
dbcon.clearDB()
.then(()=>{
console.log("parsing started\n");
let stream = parse();
stream
.on('finish',function(){
dbcon.close();
for(let dbname in dbcon.counter){
console.log(`\ninserted ${dbcon.counter[dbname]} in ${dbname}`);
}
})
.on('error',function(err){
console.log(err)
});
})
.catch(function(err){
console.error(err);
dbcon.close();
});