/
bamazon.js
109 lines (100 loc) · 2.57 KB
/
bamazon.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var mysql = require('mysql');
var config = require('./config.js');
var connection = config.connection;
// var connection = mysql.createConnection({
// host: 'localhost',
// port: 3306,
// user: 'root',
// password: config.dbpass,
// database: 'bamazondb'
// });
connection.connect(function(err){
if (err) throw err;
createProduct();
});
var mockData = [
{
product: 'Martin Acoustic Guitar',
department: 'Guitars',
price: 1499.00,
stock: 35
},
{
product: 'Les Paul Gibson SG Special Edition',
department: 'Guitars',
price: 4499.99,
stock: 5
},
{
product: 'Fender Stratocaster Guitar',
department: 'Guitars',
price: 4000.00,
stock: 25
},
{
product: 'Ernie Ball Guitar Strings',
department: 'Guitar Accessories',
price: 10.99,
stock: 100
},
{
product: 'Guitar Picking Exercises - Book 1 w/ MP3 Download',
department: 'Sheet Music',
price: 19.99,
stock: 125
},
{
product: 'Ernie Ball Guitar Picks (20 pack)',
department: 'Accessories',
price: 4.99,
stock: 500
},
{
product: 'Marshall Guitar Amplifier, 30"',
department: 'Amplifiers',
price: 999.99,
stock: 125
},
{
product: 'Electric Guitar Gig Bag',
department: 'Guitars',
price: 59.99,
stock: 200
},
{
product: 'Dr. Beat Metronome',
department: 'Accessories',
price: 89.99,
stock: 50
},
{
product: 'Guitar Tuner',
department: 'Accessories',
price: 14.99,
stock: 40
},
]
function testloop(array) {
for (var i = 0; i < array.length; i++ ) {
console.log('Product: ' + array[i].product + '\nDepartment: ' + array[i].department +'\nPrice: ' + array[i].price);
}
}
testloop(mockData);
function createProduct() {
for (var i = 0; i < mockData.length; i++ ) {
// console.log('Product: ' + array[i].product + '\nDepartment: ' + array[i].department +'\nPrice: ' + array[i].price);
var query = connection.query(
'insert into products set ?',
{
product_name: mockData[i].product,
department_name: mockData[i].department,
price: mockData[i].price,
stock_qty: mockData[i].stock
},
function(err, res) {
console.log(res);
}
)
}
connection.end();
}