-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimport_tips.js
48 lines (39 loc) · 1.01 KB
/
import_tips.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
var lineReader = require('line-reader');
var Sequelize = require('sequelize');
var sequelize = new Sequelize('tips_test', 'zx', 'admin', {
dialect: "postgres", // or 'sqlite', 'postgres', 'mariadb'
host: "172.31.214.169",
port: 5432, // or 5432 (for postgres)
});
sequelize
.authenticate()
.complete(function(err) {
if (!!err) {
console.log('Unable to connect to the database:', err)
} else {
console.log('Connection has been established successfully.')
}
});
var Tip = sequelize.define('Tip', {
content: Sequelize.STRING,
other: Sequelize.STRING
});
function read_from_file(){
var i=0;
lineReader.eachLine('content.csv', function(line, last) {
console.log(++i);
var tip = Tip.build({
content: line
});
tip
.save()
.complete(function(err) {
if (!!err) {
console.log('The instance has not been saved:', err)
} else {
console.log('We have a persisted instance now')
}
})
});
}
read_from_file();