-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimport.js
More file actions
31 lines (28 loc) · 676 Bytes
/
import.js
File metadata and controls
31 lines (28 loc) · 676 Bytes
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
var env = process.env.NODE_ENV || 'development'
var knex = require('knex')
var config = require('./knexfile')[env]
var db = knex(config)
var fs = require("fs")
var csv = require("fast-csv")
var words = []
fs.createReadStream("./words.csv")
.pipe(csv())
.on("data", function(data){
words.push({
bias: data[0],
neutral: data[1],
notes: data[2]
})
})
.on("end", function(data){
console.log(words[0].bias)
db('words').delete().then(() => {
db('words').insert(words).then(() => {
db('words').select()
.then((result) =>{
console.log(result.length)
process.exit()
})
})
})
})