Skip to content

Shadi A.#3

Open
shmoonwalker wants to merge 2 commits into
HackYourAssignment:mainfrom
shmoonwalker:main
Open

Shadi A.#3
shmoonwalker wants to merge 2 commits into
HackYourAssignment:mainfrom
shmoonwalker:main

Conversation

@shmoonwalker
Copy link
Copy Markdown

Finished tasks for week 12

…ase functions

- Added sqlite3 as a dependency in package.json.
- Created setup.sql to define decks and cards tables.
- Implemented database functions in database.js to manage decks and cards:
  - getAllDecks: retrieves all decks.
  - getDeckById: retrieves a specific deck by ID.
  - addDeck: inserts a new deck and returns it.
  - deleteDeck: removes a deck by ID.
  - getAllCardsForDeck: retrieves all cards for a specific deck.
  - addCard: inserts a new card and returns it.
  - markCardLearned: marks a card as learned.
  - deleteCard: removes a card by ID.
@github-actions
Copy link
Copy Markdown

📝 HackYourFuture auto grade

Assignment Score: 0 / 100 ✅

Status: ✅ Passed
Minimum score to pass: 0
🧪 The auto grade is experimental and still being improved

Test Details

@remarcmij remarcmij self-assigned this Mar 31, 2026
Copy link
Copy Markdown

@remarcmij remarcmij left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @shmoonwalker, there are some minor issues with task-1. In task 2, I see some inconsistencies in how you wrote some of the code. Please check my comments below.

Comment thread task-1/queries.sql
-- **Question 3** — Show every book in the database along with its author's full name. Combine `first_name` and `last_name` into a single column called `author`. _(Hint: you will need a JOIN.)_

SELECT a.first_name || ' ' || a.last_name AS author, b.title, b.genre, b.published_year FROM authors a
JOIN books b ON a.id = b.author_id
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The required terminating semicolon is missing.

Suggested change
JOIN books b ON a.id = b.author_id
JOIN books b ON a.id = b.author_id;

Comment thread task-1/queries.sql

SELECT a.first_name || ' ' || a.last_name AS author, b.title, b.published_year FROM authors a
JOIN books b ON a.id = b.author_id
WHERE author = 'Stephen King' ORDER BY published_year DESC;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For better readability, place the ORDER BY clause on a new line.

Suggested change
WHERE author = 'Stephen King' ORDER BY published_year DESC;
WHERE author = 'Stephen King'
ORDER BY published_year DESC;

Note that Question 4 does not mention that the author's name should be shown. So the following SQL may be more appropriate:

SELECT b.title, b.published_year FROM authors a
JOIN books b ON a.id = b.author_id 
WHERE a.first_name = "Stephen" AND a.last_name = "King" 
ORDER BY published_year DESC;

Comment thread task-1/queries.sql

INSERT INTO books (title, published_year,genre, author_id) VALUES
('The Story of My Cats', 2023, 'Biography',
(SELECT id FROM authors WHERE first_name = 'Shadi' AND last_name = 'Abedinpour'));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent use of a SQL subquery.

Comment thread task-1/queries.sql
Comment on lines +38 to +39
WHERE title = 'The Dark Tower: The Gunslinger';
SELECT * FROM books WHERE title = 'The Dark Tower: The Gunslinger';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use consistent indentation:

Suggested change
WHERE title = 'The Dark Tower: The Gunslinger';
SELECT * FROM books WHERE title = 'The Dark Tower: The Gunslinger';
WHERE title = 'The Dark Tower: The Gunslinger';
SELECT * FROM books WHERE title = 'The Dark Tower: The Gunslinger';

Comment thread task-1/queries.sql

-- **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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Rather than hard-coding the id, you could use a subquery here too.
  2. The required terminating semicolon is missing.
Suggested change
WHERE id = 101
WHERE id = 101;

Comment thread task-1/queries.sql
-- **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.)
SELECT a.first_name || ' ' || a.last_name AS author FROM authors a
LEFT JOIN books b ON a.id = b.author_id
WHERE b.id IS NULL; No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The full name is not required. So this alternative would also be fine:

SELECT a.first_name, a.last_name FROM authors a
LEFT JOIN books b ON a.id = b.author_id
WHERE b.id IS NULL;

Comment thread task-2/migrate.js
@@ -0,0 +1,34 @@
import fs from "fs";
import sqlite3 from "sqlite3";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this code doesn't work at all. The sqlite3 npm package is deprecated, see: https://www.npmjs.com/package/sqlite3. The db.run() function in this deprecated package is asynchronous and consequently produces this error:

[Error: SQLITE_CONSTRAINT: FOREIGN KEY constraint failed
Emitted 'error' event on Statement instance at:
] {
  errno: 19,
  code: 'SQLITE_CONSTRAINT'
}

This makes me wonder how you managed to create a populated flashcards.db file, with migrate.js being defective.

Comment thread task-2/package.json
"dependencies": {
"better-sqlite3": "^12.8.0"
"better-sqlite3": "^12.8.0",
"sqlite3": "^6.0.1"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you add the deprecated sqlite3 dependency? You only need better-sqlite3.

Comment thread task-2/src/database.js
}
const info = db.prepare("DELETE FROM cards WHERE id = ?").run(cardId);
return info.changes > 0;
} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks perfect. Perhaps too perfect to be completely your own work?

@remarcmij remarcmij added the Reviewed This assignment has been reivewed by a mentor and a feedback has been provided label Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed This assignment has been reivewed by a mentor and a feedback has been provided

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants