-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsqlqueries.js
More file actions
56 lines (55 loc) · 2.28 KB
/
Copy pathsqlqueries.js
File metadata and controls
56 lines (55 loc) · 2.28 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
const mysql = require("mysql");
const connection = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "testtidings",
});
connection.query(
"CREATE TABLE if not exists users(id INT NOT NULL AUTO_INCREMENT, email VARCHAR(25), fullname VARCHAR(25),gender VARCHAR(10), profileImg BLOB, password VARCHAR(100), PRIMARY KEY(id))",
(err, result) => {
if (err) {
console.log(err);
}
}
);
connection.query(
"CREATE TABLE if not exists tyds(id INT NOT NULL AUTO_INCREMENT, tyd VARCHAR(255),likes INT DEFAULT 0,comments INT DEFAULT 0, userId INT(20), dateposted DATETIME DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), FOREIGN KEY (userID) REFERENCES users(id))",
(err, result) => {
if (err) {
console.log(err);
}
}
);
connection.query(
"CREATE TABLE if not exists likes(id INT NOT NULL AUTO_INCREMENT, tydId INT(20),userId INT(20), PRIMARY KEY(id), FOREIGN KEY (tydId) REFERENCES tyds(id), FOREIGN KEY (userId) REFERENCES users(id))",
(err, result)=>{
if(err){
console.log(error)
}
}
)
connection.query(
"CREATE TABLE if not exists comments(id INT NOT NULL AUTO_INCREMENT,comment VARCHAR(255),dateposted DATETIME DEFAULT CURRENT_TIMESTAMP,likes INT DEFAULT 0, tydId INT(20),userId INT(20), PRIMARY KEY(id), FOREIGN KEY (tydId) REFERENCES tyds(id), FOREIGN KEY (userId) REFERENCES users(id))",
(err, result)=>{
if(err){
console.log(err)
}
}
)
connection.query(
"CREATE TABLE if not exists comments(id INT NOT NULL AUTO_INCREMENT,comment VARCHAR(255),dateposted DATETIME DEFAULT CURRENT_TIMESTAMP,likes INT DEFAULT 0, tydId INT(20),userId INT(20), PRIMARY KEY(id), FOREIGN KEY (tydId) REFERENCES tyds(id), FOREIGN KEY (userId) REFERENCES users(id))",
(err, result)=>{
if(err){
console.log(err)
}
}
)
connection.query(
"CREATE TABLE if not exists notifications(id INT NOT NULL AUTO_INCREMENT,type VARCHAR(25),dateposted DATETIME DEFAULT CURRENT_TIMESTAMP, tydId INT(20), forId INT(20),fromId INT(20), PRIMARY KEY(id), FOREIGN KEY (forId) REFERENCES users(id),FOREIGN KEY (fromId) REFERENCES users(id), FOREIGN KEY (tydId) REFERENCES tyds(id))",
(err, result)=>{
if(err){
console.log(err)
}
}
)