Diana C.#1
Conversation
…with better-sqlite3
📝 HackYourFuture auto gradeAssignment Score: 0 / 100 ✅Status: ✅ Passed Test Details |
rafasilpereira
left a comment
There was a problem hiding this comment.
Well done! 👏 👏
Both tasks were succesfully implemented with a clear and solid code!
|
|
||
| --Question 6** — Add one book for the author you just inserted. It can be a real book or a made-up one. | ||
| INSERT INTO books (title, published_year, genre, author_id) | ||
| VALUES ('Spaces',2005, 'Fantasy', 25); |
There was a problem hiding this comment.
Good! A challenge: there is a way of doing a SELECT to find the author_id. How would you do that? Tip: I can add doing something like ...VALUES('Rafael', 'Pereira', (SELECT id FROM customers)) ;)
| --Question 7** — The genre for "The Dark Tower: The Gunslinger" was entered incorrectly as `'Fantasy'`. It should be `'Horror'`. Write an UPDATE to fix it, then verify the change with a SELECT. | ||
| UPDATE books | ||
| SET genre = 'Horror' | ||
| WHERE title = 'The Dark Tower: The Gunslinger'; |
There was a problem hiding this comment.
Good one here! Adding exactly the title for UPDATE or DELETE and avoiding using LIKE makes you changing one what is needed, without the risk of updating or deleting not wanted rows
|
|
||
| --Question 8** — Delete the book you added in Question 6. Make sure your query targets only that specific row. | ||
| DELETE FROM books | ||
| WHERE books.id = 101; |
There was a problem hiding this comment.
How would write this if you don't know the id to be deleted? Just a thing to consider if you have a database with many rows ;)
|
|
||
| -- **Bonus B** — Find any authors in the database who have no books at all. _(Hint: you will need a LEFT JOIN and check for NULL.) | ||
| --**Bonus A** — How many books are there per genre? Show the genre name and the count, ordered from most to fewest books. | ||
| SELECT genre, COUNT(*) AS book_count |
There was a problem hiding this comment.
Well done in using an ALIAS! Makes more clear and logic to use in code later!
|
|
||
| // Open the database file. | ||
| // If the file doesn't exist, better-sqlite3 will create it. | ||
| const db = new Database("data/flashcards.db"); |
There was a problem hiding this comment.
Very solid and direct implementation of the migration! 👏
…with better-sqlite3