-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.js
38 lines (32 loc) · 871 Bytes
/
model.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
const db = require("./db/connection");
function getRepo() {
return db.query(
`
SELECT * FROM projects;
`
);
}
function saveRepo(repo) {
console.log(repo.project_name);
return db.query(
"INSERT INTO projects( week, project_name, project_screenshot, collaborators, project_link) VALUES($1, $2, $3, $4, $5)",
[
repo.project_week,
repo.project_name,
repo.project_screenshot,
repo.project_collaborators,
repo.github_link,
]
);
}
function getUser(user) {
return db
.query("SELECT * FROM users WHERE username = ($1);", [user])
.then((res) => res.rows[0]);
}
function deleteRepo(id) {
console.log(id);
return db.query("DELETE FROM projects WHERE ($1)=id", [id]);
}
module.exports = { saveRepo, getRepo, getUser, deleteRepo };
// return db.query("DELETE FROM img_posts WHERE ($1)=id", [postId])