-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
69 lines (61 loc) · 2.17 KB
/
script.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
const mysql = require("mysql");
//Create connection
const db = mysql.createConnection({
host : 'localhost',
user: 'root',
password : '',
database: 'test1' //to use the ccsql database
});
//Connect
db.connect((err)=>{
if(err){
throw err;
}
console.log('Mysql connected..')
})
//First
const firstTable=()=>{
return new Promise((resolve,reject)=>{
let sql1 = 'CREATE TABLE usertable(id VARCHAR(40), name VARCHAR(255),password CHAR(255), email VARCHAR(255), address VARCHAR(255), phnum VARCHAR(10), paymentid VARCHAR(255), rating int(1), PRIMARY KEY(id))';
db.query(sql1 , (err, result)=>{
if(err) reject(err);
resolve("User Table Created")
})
})
}
//Second
const secondTable=()=>{
return new Promise((resolve,reject)=>{
let sql2 = 'CREATE TABLE jobtable(id VARCHAR(40), description VARCHAR(255), maxwage int(2), durationto TIME(0), durationfrom TIME(0), status VARCHAR(255), PRIMARY KEY(id),timestamp TIMESTAMP,workerid VARCHAR(40), FOREIGN KEY (workerid) REFERENCES usertable(id),empid VARCHAR(40),FOREIGN KEY (empid) REFERENCES usertable(id))';
db.query(sql2 , (err, result)=>{
if(err) reject(err);
resolve("Job Table Created");
})
})
}
//Third
const thirdTable=()=>{
return new Promise((resolve,reject)=>{
let sql3 = 'CREATE TABLE bidtable(id VARCHAR(40),status VARCHAR(255),jobid VARCHAR(40), FOREIGN KEY (jobid) REFERENCES jobtable(id),bidderid VARCHAR(40),FOREIGN KEY (bidderid) REFERENCES usertable(id), duration VARCHAR(5),PRIMARY KEY(id))';
db.query(sql3 , (err, result)=>{
if(err) throw err;
resolve("Bid Table Created");
// console.log(result);
})
})
}
firstTable().then(res1=>{
console.log(res1);
secondTable().then(res2=>{
console.log(res2)
thirdTable().then(res3=>{
console.log("Bid Table Created");
}).catch((err)=>{
console.log("Error in Bid table.")
})
}).catch((err)=>{
console.log("Error in Job table.")
})
}).catch(err=>{
console.log("Error in User table.")
})