Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"editor.inlineSuggest.enabled": false,
"github.copilot.enable": {
"javascript": false
"*": true,
"plaintext": false,
"markdown": false,
"scminput": false,
"javascript": true
}
}
Binary file modified task-1/books_library.db
Binary file not shown.
33 changes: 33 additions & 0 deletions task-1/queries.sql
Original file line number Diff line number Diff line change
@@ -1,20 +1,53 @@
---- 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
b.title,
a.first_name || ' ' || a.last_name AS author
FROM books b
INNER JOIN authors a ON a.id = b.author_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
b.title,
b.published_year,
a.first_name || ' ' || a.last_name AS author
FROM books b
INNER JOIN authors a ON a.id = b.author_id
WHERE a.first_name || ' ' || a.last_name = 'Stephen King'
ORDER BY published_year;



-- **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 ('Salem', 'Ba-Rabuod', 'Yemeni', 1990);

-- **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 ('The Journey of Salem', 2026, 'Biography', 26);

-- **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';


-- **Question 8** — Delete the book you added in Question 6. Make sure your query targets only that specific row.
Delete from books where title = 'The Journey of Salem' AND author_id = 26;

---

Expand Down
24 changes: 12 additions & 12 deletions task-2/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,46 @@ import {
markCardLearned,
deleteCard,
deleteDeck,
} from "./src/database.js";
} from './src/database.js';

console.log("=== Flashcard App ===\n");
console.log('=== Flashcard App ===\n');

// 1. List all decks
console.log("All decks:");
console.log('All decks:');
const decks = getAllDecks();
decks.forEach((deck) => {
console.log(` [${deck.id}] ${deck.name} — ${deck.description}`);
});

// 2. Get a single deck by id
console.log("\nLooking up deck 2:");
console.log('\nLooking up deck 2:');
const deck2 = getDeckById(2);
console.log(` Found: ${deck2.name}`);

// 3. Show all cards in deck 1
console.log('\nCards in "JavaScript Basics" (deck 1):');
const cards = getAllCardsForDeck(1);
cards.forEach((card) => {
const status = card.learned ? "✓ learned" : "○ not yet";
const status = card.learned ? '✓ learned' : '○ not yet';
console.log(` [${card.id}] ${status} Q: ${card.question}`);
});

// 4. Add a new deck
console.log("\nAdding a new deck...");
const newDeck = addDeck("Git & GitHub", "Version control basics");
console.log('\nAdding a new deck...');
const newDeck = addDeck('Git & GitHub', 'Version control basics');
console.log(` Created: [${newDeck.id}] ${newDeck.name}`);

// 5. Add a card to the new deck
console.log("\nAdding a card to the new deck...");
console.log('\nAdding a card to the new deck...');
const newCard = addCard(
"What is a commit?",
"A snapshot of your changes saved to the repository",
'What is a commit?',
'A snapshot of your changes saved to the repository',
newDeck.id,
);
console.log(` Created card [${newCard.id}]: "${newCard.question}"`);

// 6. Mark a card as learned
console.log("\nMarking card 1 as learned...");
console.log('\nMarking card 1 as learned...');
const updated = markCardLearned(1);
console.log(` Card 1 learned status is now: ${updated.learned}`);

Expand All @@ -65,4 +65,4 @@ console.log(`\nDeleting deck ${newDeck.id}...`);
const deckDeleted = deleteDeck(newDeck.id);
console.log(` Deleted: ${deckDeleted}`);

console.log("\n=== Done ===");
console.log('\n=== Done ===');
Binary file added task-2/data/flashcards.db
Binary file not shown.
33 changes: 33 additions & 0 deletions task-2/migrate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import fs from 'node:fs';
import Database from 'better-sqlite3';

const data = fs.readFileSync('data/data.json', 'utf-8');
const content = JSON.parse(data);

const dataMigrate = new Database('data/flashcards.db');

const insertDecks = dataMigrate.prepare(`
INSERT INTO decks (name, description)
VALUES (@name, @description)
`);

for (const deck of content.decks) {
insertDecks.run({
name: deck.name,
description: deck.description,
});
}

const insertCards = dataMigrate.prepare(`
INSERT INTO cards (question, answer, learned, deck_id)
VALUES (@question, @answer, @learned, @deck_id)
`);

for (const card of content.cards) {
insertCards.run({
question: card.question,
answer: card.answer,
learned: card.learned ? 1 : 0,
deck_id: card.deckId,
});
}
Loading