-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogs_repository.js
51 lines (42 loc) · 1.26 KB
/
logs_repository.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
const query = require("./connection.js").query
async function getBooks(user) {
return await query(`select *
from books
where user_id = $1`, user);
}
async function getBook(id) {
return await query(`select *
from books
where id = $1`, id)
}
async function getEntries(book) {
return await query(`select *
from entries
where book_id = $1`, book);
}
async function addEntry(bid, text, where, when) {
return await query(`insert into entries(book_id, text, "where", "when" )
values($1, $2, $3, $4)`, bid, text, where, when);
}
async function addBook(name, creator) {
return await query(`insert into books("name", user_id ) VALUES($1, $2)`, name, creator);
}
async function deleteBook(id) {
return await query(`delete
from books
where id = $1`, id)
}
async function updateBook(id, newName) {
return await query(`update books
set "name" = $1
where id = $2`, newName, id)
}
module.exports = {
addBook,
addEntry,
getBooks,
getEntries,
getBook,
deleteBook,
updateBook
}