-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport.js
42 lines (34 loc) · 914 Bytes
/
import.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
require('dotenv').config()
const pg = require('pg')
const makeInsertAverageSalaries = require('./repo/averagesalaries/insert')
const readFileSync = require('fs').readFileSync
const pgPool = new pg.Pool({
connectionString: process.env.DATABASE_URL,
ssl: {
rejectUnauthorized: false
}
})
const file = readFileSync('./hjukrunarfraedingar.csv')
const data = file.toString().split('\n').slice()
const arr = data.map(line => {
const columns = line.split(';')
return [
1,
columns[0], // period
columns[1], // employment,
columns[2], // daytime
columns[3], // overtime
columns[4], // shift
columns[5], // other
columns[6], // total
columns[7] // genderid
]
})
if (arr[arr.length - 1][2] === undefined) {
arr.pop()
}
console.log(arr)
const insertAverageSalaries = makeInsertAverageSalaries(pgPool)
insertAverageSalaries(arr).then(res => {
console.log(res)
})