Hannah N#9
Conversation
📝 HackYourFuture auto gradeAssignment Score: 0 / 100 ✅Status: ✅ Passed Test Details |
|
|
||
| SELECT title,published_year FROM books b | ||
| WHERE b.genre = "Science Fiction" | ||
| ORDER BY b.published_year ASC ; |
There was a problem hiding this comment.
- For better readability, add a space after a comma.
- If you have only one table, there can be no confusion as to which field belongs to which table. You therefore do not need to prefix the field names with the table name (or alias):
SELECT title, published_year FROM books
WHERE genre = "Science Fiction"
ORDER BY published_year ASC;| -- **Question 2** — Show every book published before 1950. Display the title and year only. | ||
|
|
||
| SELECT title,published_year FROM books b | ||
| WHERE b.published_year < 1950; |
|
|
||
| SELECT b.title,a.first_name || ' ' || a.last_name AS author | ||
| FROM books b | ||
| JOIN authors a ON b.author_id = a.id; |
There was a problem hiding this comment.
Here, you indeed need to prefix the field name id with the table name because both tables have an id field. Strictly speaking, that is the only field that needs a prefix. But your version with table prefixes is preferred and more robust than the minimal version shown below. That version makes assumptions about the uniqueness of some fields, which may not hold in the future if more fields are added.
SELECT title, first_name || ' ' || last_name AS author
FROM books
JOIN authors a ON author_id = a.id;| CREATE TABLE decks( | ||
| id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
| name TEXT NOT NULL, | ||
| description TEXT | ||
| ); |
There was a problem hiding this comment.
Be consistent with indentation:
| CREATE TABLE decks( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| name TEXT NOT NULL, | |
| description TEXT | |
| ); | |
| CREATE TABLE decks( | |
| id INTEGER PRIMARY KEY AUTOINCREMENT, | |
| name TEXT NOT NULL, | |
| description TEXT | |
| ); |
| console.log(`Added card: ${card.question}`); | ||
| } | ||
|
|
||
| console.log("Migration done! All decks and cards are in the database."); |
| @@ -21,47 +21,108 @@ const db = new Database(DB_FILE); | |||
|
|
|||
| export function getAllDecks() { | |||
| // TODO: return all rows from the decks table | |||
There was a problem hiding this comment.
Remove the TODO comments once they are done.
| try{ | ||
|
|
||
| const decks = db.prepare("SELECT * FROM decks").all(); | ||
|
|
||
| return decks;} | ||
| catch(err){ | ||
| throw new Error(`Failed to get all decks: ${err.message}`); | ||
| } |
There was a problem hiding this comment.
It was not necessary to create try/catch blocks here. But if you do, make sure that you format them correctly (Prettier should do this automatically, if your VS Code is configured correctly).
try {
const decks = db.prepare("SELECT * FROM decks").all();
return decks;
} catch(err){
throw new Error(`Failed to get all decks: ${err.message}`);
}|
|
||
| return result.changes > 0; | ||
| }catch(err){ | ||
| throw new Error(`Failed to delete deck with id ${id}: ${err.message}`); |
There was a problem hiding this comment.
The id variable in the catch block is undefined.
| try{ | ||
| // TODO: return all card rows whose deckId matches | ||
| throw new Error('Not implemented'); | ||
| return db.prepare("SELECT id, question, answer, learned, deck_id AS deckId FROM cards WHERE deck_id = ?").all(deckId); |
There was a problem hiding this comment.
You are returning learned as a number. The JSON version returned it as a boolean.
No description provided.