1
1
'use strict' ;
2
2
3
- var papa = require ( 'papaparse' ) ;
4
- var fs = require ( 'fs' ) ;
3
+ const papa = require ( 'papaparse' ) ;
4
+ const fs = require ( 'fs' ) ;
5
5
6
6
//
7
7
// Read a text file form the file system.
8
8
//
9
- var read = function ( fileName ) {
9
+ function read ( fileName ) {
10
10
return new Promise ( ( resolve , reject ) => {
11
11
fs . readFile ( fileName , 'utf8' ,
12
12
function ( err , textFileData ) {
@@ -24,18 +24,18 @@ var read = function (fileName) {
24
24
//
25
25
// Helper function to import a CSV file.
26
26
//
27
- var importCsvFile = function ( filePath ) {
27
+ function importCsvFile ( filePath ) {
28
28
return read ( filePath )
29
29
. then ( textFileData => {
30
- var result = papa . parse ( textFileData , {
30
+ const result = papa . parse ( textFileData , {
31
31
header : true ,
32
32
dynamicTyping : true ,
33
33
} ) ;
34
34
return result . data ;
35
35
} ) ;
36
36
} ;
37
37
38
- var exportToMySql = function ( db , tableName , data ) {
38
+ function exportToMySql ( db , tableName , data ) {
39
39
return data . reduce (
40
40
( prevPromise , record ) =>
41
41
prevPromise . then ( ( ) =>
@@ -48,9 +48,9 @@ var exportToMySql = function (db, tableName, data) {
48
48
) ;
49
49
} ;
50
50
51
- var mysql = require ( 'nodejs-mysql' ) . default ;
51
+ const mysql = require ( 'nodejs-mysql' ) . default ;
52
52
53
- var config = {
53
+ const config = {
54
54
host : 'localhost' ,
55
55
port : 3306 ,
56
56
user : 'root' ,
@@ -62,9 +62,9 @@ var config = {
62
62
connectTimeout : 0 ,
63
63
} ;
64
64
65
- var db = mysql . getInstance ( config ) ;
65
+ const db = mysql . getInstance ( config ) ;
66
66
67
- var createDbCmd =
67
+ const createDbCmd =
68
68
"create table largest_earthquakes ( Magnitude double, Time datetime, Latitude double, Longitude double, `Depth/Km` double )" ;
69
69
70
70
db . exec ( createDbCmd )
0 commit comments