Atiqa N. - #18
Atiqa N.#18atiqanaseer wants to merge 2 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
📝 HackYourFuture auto gradeAssignment Score: 0 / 100 ✅Status: ✅ Passed Test Details |
rafasilpereira
left a comment
There was a problem hiding this comment.
Well done on delivering this assignment!
Task 1 is well done and with good queries implementations. I would only pay attention about details about the requirements for the questions and thiking how we would do this queries with a larger data quantity.
Task 2 is working properly and as expected! I would like to understand better the use of maps and casting, curious to see what motivated this choise!
| -- **Question 2** — Show every book published before 1950. Display the title and year only. | ||
|
|
||
| SELECT title, published_year FROM books | ||
| WHERE published_year < 50; |
There was a problem hiding this comment.
This would only show very old books less than year 50, and that's why this query doesn't return results. Did you try with 1950?
| SELECT b.title, b.published_year | ||
| FROM books b | ||
| JOIN authors a ON a.id = b.author_id | ||
| WHERE a.first_name || ' ' || a.last_name = 'Stephen King' |
There was a problem hiding this comment.
Good one on choosing using concatenation in WHERE!
| -- **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 ('Sunset Rose', '2026', 'Romance', 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 id = 101; |
There was a problem hiding this comment.
How would write this if you don't know the id to be deleted?
| const migrate = db.transaction(() => { | ||
| // Clear existing rows so the migration can be re-run safely. | ||
| db.prepare('DELETE FROM cards').run(); | ||
| db.prepare('DELETE FROM decks').run(); |
There was a problem hiding this comment.
Good approach on deleting before!
| .run(name, description); | ||
|
|
||
| return { | ||
| id: Number(info.lastInsertRowid), |
There was a problem hiding this comment.
Why are you using casting in this row?
| ) | ||
| .all(deckId); | ||
|
|
||
| return rows.map(card => ({ ...card, learned: Boolean(card.learned) })); |
There was a problem hiding this comment.
Why did you choose to map and cast the returns in this line?
No description provided.