-
Notifications
You must be signed in to change notification settings - Fork 18
Pavel T #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pavel-tisner
wants to merge
3
commits into
HackYourAssignment:main
Choose a base branch
from
pavel-tisner:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Pavel T #17
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,51 @@ | ||
| ---- Queries | ||
|
|
||
|
|
||
| -- **Question 1** — List the title and published year of every book in the `'Science Fiction'` genre, ordered by published year (oldest first). | ||
| 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 | ||
| WHERE published_year < 1950 | ||
|
|
||
| -- **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 | ||
| books.title, | ||
| authors.first_name || ' ' || authors.last_name AS author | ||
| FROM books | ||
| JOIN authors ON books.author_id = authors.id; | ||
|
|
||
| -- **Question 4** — List all books written by Stephen King. Show the title and published year, ordered by year. _(Hint: JOIN the two tables and filter on the author's name.)_ | ||
| SELECT | ||
| books.title, | ||
| books.published_year | ||
| FROM books | ||
| JOIN authors ON books.author_id = authors.id | ||
| WHERE authors.first_name = 'Stephen' | ||
| AND authors.last_name = 'King' | ||
| ORDER BY books.published_year ASC; | ||
|
|
||
| -- **Question 5** — Add yourself as a new author. Use your real name, or make one up. Pick any nationality and birth year. | ||
| INSERT INTO authors (first_name, last_name, nationality, birth_year) | ||
| VALUES ('Pavel', 'Tisner', 'Russian', 1987); | ||
|
|
||
| -- **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 ('My way', 2026, 'Fiction', (SELECT id FROM authors WHERE last_name = 'Tisner')); | ||
|
|
||
| -- **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 = 'Fantasy' | ||
| WHERE title = 'Harry Potter and the Deathly Hallows'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The title is wrong here. It wasn't expected to be Harry Potter. |
||
|
|
||
| -- **Question 8** — Delete the book you added in Question 6. Make sure your query targets only that specific row. | ||
| DELETE FROM books | ||
| WHERE title = 'My way' | ||
| AND published_year = 2026; | ||
|
|
||
| --- | ||
|
|
||
|
|
||
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import fs from 'fs'; | ||
| import Database from 'better-sqlite3'; | ||
|
|
||
| const data = JSON.parse(fs.readFileSync('data/data.json', 'utf-8')); | ||
| const db = new Database('data/flashcards.db'); | ||
|
|
||
| for (const deck of data.decks) { | ||
| db.prepare('INSERT INTO decks (name, description) VALUES (@name, @description)') | ||
| .run({ | ||
| name: deck.name, | ||
| description: deck.description | ||
| }); | ||
| } | ||
|
|
||
| for (const card of data.cards) { | ||
| db.prepare('INSERT INTO cards (question, answer, learned, deck_id) VALUES (@question, @answer, @learned, @deck_id)') | ||
| .run({ | ||
| question: card.question, | ||
| answer: card.answer, | ||
| learned: card.learned ? 1 : 0, | ||
| deck_id: card.deckId | ||
| }); | ||
| } | ||
|
|
||
| db.close(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a very good solution. Here, I would recommend add more fields to the WHERE (not just the last name
Tisner), to avoid get users with the same last name.