-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlibrary.sql
More file actions
48 lines (46 loc) · 1.66 KB
/
library.sql
File metadata and controls
48 lines (46 loc) · 1.66 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
-- name: init_library &
--
-- Initializes the demo library
--
CREATE TABLE library (
book_author TEXT,
book_title TEXT,
loaned_to TEXT,
loaned_on DATETIME
);
INSERT INTO library (book_author, book_title) VALUES ('Jane Austen', 'Pride and Prejudice');
INSERT INTO library (book_author, book_title) VALUES ('Charlotte Bronte', 'Jane Eyre');
INSERT INTO library (book_author, book_title) VALUES ('Leo Tolstoy', 'War and Peace');
INSERT INTO library (book_author, book_title) VALUES ('Gustave Flaubert', 'Madame Bovary');
INSERT INTO library (book_author, book_title) VALUES ('George Eliot', 'Middlemarch');
INSERT INTO library (book_author, book_title) VALUES ('John Milton', 'Paradise Lost');
INSERT INTO library (book_author, book_title) VALUES ('Patrick O’Brian', 'Master and Commander');
INSERT INTO library (book_author, book_title) VALUES ('Margaret Mitchell', 'Gone With the Wind');
INSERT INTO library (book_author, book_title) VALUES ('Boris Pasternak', 'Doctor Zhivago');
INSERT INTO library (book_author, book_title) VALUES ('J. R. R. Tolkien', 'The Lord of the Rings');
INSERT INTO library (book_author, book_title) VALUES ('A. A Milne', 'Winnie the Pooh');
-- name: get_loaned_books ?
--
-- Returns the list of books loaned to a patron
--
-- # Parameters
--
-- param: user_id: &str - user ID
--
SELECT book_title
FROM library
WHERE loaned_to = :user_id
ORDER BY 1
-- name: loan_books!
--
-- Updates the book records to reflect loan to a patron
--
-- # Parameters
--
-- param: book_titles: &str - book titles
-- param: user_id: &str - user ID
--
UPDATE library
SET loaned_to = :user_id
, loaned_on = current_timestamp
WHERE book_title IN (:book_titles)