-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_script.js
More file actions
79 lines (72 loc) · 2.97 KB
/
db_script.js
File metadata and controls
79 lines (72 loc) · 2.97 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* Created by jisooyoon on 2017. 4. 21..
*/
var csv = require('csv-parser');
var fs = require('fs');
var db = require('./db');
var _ = require('underscore');
/**
* AUTH: yjsgoon
* DESC: beer
* DATE: 2017. 5. 6.
*/
fs.createReadStream('./resource/db/mclang_brewery_beer.csv')
.pipe(csv())
.on('data', function (data) {
// console.log('id: %s beer_image: %s engname: %s korname: %s feature: %s style: %s released date: %s ' +
// 'IBU: %s ABV: %s about: %s is_beer: %s is_brewery_detail: %s brewery_id: %s',
// data.id, data.beer_image, data.engname, data.korname, data.feature, data.style, data.released_date,
// data.IBU, data.ABV, data.about, data.is_beer, data.is_brewery_detail, data.brewery_id);
var abv = data.ABV;
var ibu = data.IBU;
if (!_.isNumber(data.ABV))
abv = -1;
if (!_.isNumber(data.IBU))
ibu = -1;
db.query("INSERT INTO beer(field_id, beer_engname, beer_korname, beer_image, nation_id, style_id, " +
"beer_abv, beer_ibu, beer_feature, brewery_id, history, description, ipt_date, upt_date) " +
"VALUES(2, ?, ?, ?, 1, 1, ?, ?, ?, ?, ?, 'need kcal', now(), now());",
[data.engname, data.korname, data.beer_image, data.abv, ibu, data.feature, data.brewery_id, data.about])
.then(function () {
console.log('script success');
})
.catch(function (err) {
console.log('script fail: ' + err);
});
});
/**
* AUTH: yjsgoon
* DESC: brewery
* DATE: 2017. 5. 1.
*/
// fs.createReadStream('./resource/db/mclang_brewery_brewery.csv')
// .pipe(csv())
// .on('data', function (data) {
// db.query("INSERT INTO brewery(brewery_engname, brewery_korname, brewery_location, brewery_location_detail, " +
// "brewery_tel, brewery_history, brewery_url, ipt_date, upt_date) VALUES(?, ?, ?, ?, ?, ?, ?, now(), now());",
// [data.engname, data.korname, data.location, data.location_detail,
// data.phone, data.description, data.homepage])
// .then(function () {
// console.log('script success');
// })
// .catch(function (err) {
// console.log('script fail: ' + err);
// });
// });
/**
* AUTH: yjsgoon
* DESC: pub
* DATE: 2017. 5. 3.
*/
// fs.createReadStream('./resource/db/mclang_brewery_pub.csv')
// .pipe(csv())
// .on('data', function (data) {
// db.query("INSERT INTO pub(pub_engname, pub_korname, pub_location, pub_brewery_id, ipt_date, upt_date) VALUES(?, ?, ?, ?, now(), now());",
// [data.engname, data.korname, data.location, data.brewery_id])
// .then(function () {
// console.log('script success');
// })
// .catch(function (err) {
// console.log('script fail: ' + err);
// });
// });