-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.js
68 lines (59 loc) · 1.36 KB
/
db.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
const mysql = require('mysql');
const con = mysql.createConnection({
host:'localhost',
user:'root',
password:'slrlal1!',
port:3306,
database:'netflix',
multipleStatements: true
});
con.connect((err) => {
if (err) throw err;
else console.log("connection success!!");
})
function getMovie(callback){
con.query('select * from movie',(err,rows,fields)=>{
if(err) console.log("getMovie err"+err);
callback(rows);
});
}
function getDrama(callback){
con.query('select * from drama',(err,rows,fields)=>{
if(err) console.log("getDrama err"+err);
callback(rows);
});
}
function getTv(callback){
con.query('select * from tv', (err ,rows)=> {
if(err) {
console.error(err)
return err;
} else {
callback(rows);
}
});
}
// const tvData = await getTv();
// if (!tvData) {
// console.log("Empty")
// }
function getTvRank(callback){
con.query('select tv.rank from tv',(err,rows,fields)=>{
if(err) console.log("getTvRank err"+err);
callback(rows);
})
}
function recommendPlus(id,callback){
con.query(`update tv set rank=rank+1 where id=${id}`,(err,row,fields)=>{
if(err) throw err;
callback(row);
});
}
module.exports = {
getMovie,
getDrama,
getTv,
recommendPlus,
con,
getTvRank
}