-
Notifications
You must be signed in to change notification settings - Fork 0
/
stockit.js
45 lines (42 loc) · 1.13 KB
/
stockit.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
//require node packages
const inquirer = require('inquirer');
const mysql = require('mysql');
//connect to mysql database
const connection = mysql.createConnection({
host:"localhost",
port: 3306,
user: "root",
password: "Kafka#678",
database:"bamazon_DB"
});
connection.connect(function(err) {
if (err) throw err;
console.log("connect as id " + connection.threadId);
addProducts();
afterConnection()
})
//insert info for 10 random 'mock' items into database
function addProducts() {
console.log("Inserting new product..\.n");
let query = connection.query(
"INSERT INTO products SET?",
{
product_name: 'microwave',
department_name: 'home and kitchen',
price: 30,
stock_quantity: 10
},
function(err,res) {
console.log(res.affectedRows + " product inserted!\n");
//addProducts();
}
);
console.log(query.sqp);
}
function afterConnection() {
connection.query("SELECT * FROM products", function(err, res) {
if (err) throw err;
console.log(res);
connection.end();
})
}