forked from HackYourFuture/databases
-
Notifications
You must be signed in to change notification settings - Fork 3
Ilias_Khugaev-w1-Databases #5
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
Narpimers
wants to merge
2
commits into
HackYourAssignment:main
Choose a base branch
from
Narpimers:Ilias_Khugaev-w1-Databases
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
Changes from all commits
Commits
Show all changes
2 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
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,41 @@ | ||
| import mysql from 'mysql2/promise'; | ||
|
|
||
| // Create the connection to database | ||
| const connection = await mysql.createConnection({ | ||
| host: 'localhost', | ||
| user: 'hyfuser', | ||
| password: 'hyfpassword' | ||
| }); | ||
|
|
||
| connection.connect(); | ||
|
|
||
| try { | ||
| await connection.query('CREATE DATABASE IF NOT EXISTS meetup'); | ||
| await connection.query('USE meetup'); | ||
| await connection.query('CREATE TABLE Invitee (invitee_no INT PRIMARY KEY AUTO_INCREMENT, invitee_name VARCHAR(25) NOT NULL, invited_by VARCHAR(25))'); | ||
| await connection.query('CREATE TABLE Room (room_no INT PRIMARY KEY AUTO_INCREMENT, room_name VARCHAR(25) NOT NULL, floor_number TINYINT NOT NULL)'); | ||
| await connection.query('CREATE TABLE Meeting (meeting_no INT PRIMARY KEY AUTO_INCREMENT, meeting_title VARCHAR(40) NOT NULL, staring_time DATETIME, ending_time DATETIME, room_no INT NOT NULL)'); | ||
|
|
||
| await connection.query('INSERT INTO Invitee VALUES (1, "Ilias Khugaev", "Ilia Bubnov")'); | ||
| await connection.query('INSERT INTO Invitee VALUES (2, "Anna Petrova", "Ilias Khugaev")'); | ||
| await connection.query('INSERT INTO Invitee VALUES (3, "Dmitry Sokolov", "Anna Petrova")'); | ||
| await connection.query('INSERT INTO Invitee VALUES (4, "Maria Ivanova", "Dmitry Sokolov")'); | ||
| await connection.query('INSERT INTO Invitee VALUES (5, "Oleg Smirnov", "Maria Ivanova")'); | ||
|
|
||
| await connection.query('INSERT INTO Room VALUES (1, "Orion", 1)'); | ||
| await connection.query('INSERT INTO Room VALUES (2, "Pegasus", 1)'); | ||
| await connection.query('INSERT INTO Room VALUES (3, "Centauri", 2)'); | ||
| await connection.query('INSERT INTO Room VALUES (4, "Andromeda", 2)'); | ||
| await connection.query('INSERT INTO Room VALUES (5, "Phoenix", 3)'); | ||
|
|
||
| await connection.query('INSERT INTO Meeting VALUES (1, "Project Kickoff", "2025-05-21 09:00:00", "2025-05-21 10:00:00", 1)'); | ||
| await connection.query('INSERT INTO Meeting VALUES (2, "Design Review", "2025-05-21 10:30:00", "2025-05-21 11:30:00", 2)'); | ||
| await connection.query('INSERT INTO Meeting VALUES (3, "Sprint Planning", "2025-05-21 12:00:00", "2025-05-21 13:00:00", 3)'); | ||
| await connection.query('INSERT INTO Meeting VALUES (4, "Client Sync", "2025-05-21 14:00:00", "2025-05-21 15:00:00", 4)'); | ||
| await connection.query('INSERT INTO Meeting VALUES (5, "Retrospective", "2025-05-21 16:00:00", "2025-05-21 17:00:00", 5)'); | ||
|
|
||
| } catch (error) { | ||
| console.log(error); | ||
| } | ||
|
|
||
| connection.end(); | ||
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,39 @@ | ||
| import mysql from 'mysql2/promise'; | ||
|
|
||
| // Create the connection to database | ||
| const connection = await mysql.createConnection({ | ||
| host: 'localhost', | ||
| user: 'hyfuser', | ||
| password: 'hyfpassword' | ||
| }); | ||
|
|
||
| connection.connect(); | ||
|
|
||
| try { | ||
| await connection.query('USE new_world'); | ||
| // What are the names of countries with population greater than 8 million | ||
| await connection.query('SELECT name FROM country WHERE population > 8000000'); | ||
| // What are the names of countries that have “land” in their names? | ||
| await connection.query('SELECT name FROM country WHERE name LIKE "%land%"'); | ||
| // What are the names of the cities with population in between 500,000 and 1 million? | ||
| await connection.query('SELECT name FROM city WHERE population BETWEEN 500000 AND 1000000'); | ||
| // What's the name of all the countries on the continent ‘Europe’? | ||
| await connection.query('SELECT name FROM country WHERE Continent = "Europe"'); | ||
| // List all the countries in the descending order of their surface areas. | ||
| await connection.query('SELECT name FROM country ORDER BY SurfaceArea DESC'); | ||
| // What are the names of all the cities in the Netherlands? | ||
| await connection.query('SELECT name FROM city WHERE CountryCode = "NLD"'); | ||
| // What is the population of Rotterdam? | ||
| await connection.query('SELECT name, Population FROM city WHERE name = "Rotterdam"'); | ||
| // What's the top 10 countries by Surface Area? | ||
| await connection.query('SELECT name FROM country ORDER BY SurfaceArea DESC LIMIT 10'); | ||
| // What's the top 10 most populated cities? | ||
| await connection.query('SELECT name, Population FROM city ORDER BY population DESC LIMIT 10'); | ||
| // What is the population number of the world? | ||
| await connection.query('SELECT SUM(Population) FROM country'); | ||
|
|
||
| } catch (error) { | ||
| console.error(error); | ||
| } | ||
|
|
||
| connection.end(); |
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.
If you add
AUTO_INCREMENTforinvitee_nothen you don't need to specify 1,2,3,4,5 when inserting new invitees.