forked from HackYourFuture/databases
-
Notifications
You must be signed in to change notification settings - Fork 3
rizan_ibrahim-w1-database #7
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
rizan-ibrahim
wants to merge
4
commits into
HackYourAssignment:main
Choose a base branch
from
rizan-ibrahim:rizan_ibrahim-w1-database
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
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,70 @@ | ||
| import mysql from "mysql2"; | ||
| const connection = mysql.createConnection({ | ||
| host: "localhost", | ||
| user: "hyfuser", | ||
| password: "hyfpassword", | ||
| multipleStatements: true, | ||
| }); | ||
|
|
||
| const setUpQueries = ` | ||
| DROP DATABASE IF EXISTS meetup; | ||
| create database meetup; | ||
| use meetup; | ||
|
|
||
| /* create invite table */ | ||
|
|
||
| create table invitee( | ||
| invitee_no int auto_increment primary key, | ||
| invitee_name varchar(100), | ||
| invitee_by varchar(100) | ||
| ); | ||
|
|
||
| /* create room table */ | ||
|
|
||
| create table room ( | ||
| room_no int auto_increment primary key, | ||
| room_name varchar (100), | ||
| floor_no TINYINT UNSIGNED, | ||
| ); | ||
|
|
||
| /* create meeting table */ | ||
|
|
||
| create table meeting ( | ||
| meeting_no int auto_increment primary key, | ||
| meeting_title varchar(200), | ||
| starting_time DATETIME, | ||
| ending_time DATETIME, | ||
| room_no int, foreign key (room_no) references room (room_no) | ||
| ); | ||
|
|
||
| /* inserting 5 invitees */ | ||
|
|
||
| insert into invitee (invite_name,invite_by) | ||
| values ('rizan','stas'),('ibrahim','gea'),('araz','ahmed'),('sara','stas'),('jasmin','shero'); | ||
|
|
||
|
|
||
| /* inserting 5 rooms */ | ||
| insert into room (room_name,room_no) | ||
| values ('room1',1),('room2',2),('room3',3),('room4',4),('room5',5); | ||
|
|
||
|
|
||
| /* inserting meeting */ | ||
|
|
||
| insert into meeting (meeting_title,starting_time,ending_time,room_no) | ||
| values ('career-session', '2025-05-21 11:00:00', '2025-05-21 13:00:00', 1), | ||
| ('product', '2025-05-20 11:30:00', '2025-05-20 18:30:00', 2), | ||
| ('android-workshop', '2025-05-21 15:30:00', '2025-05-21 20:30:00', 3), | ||
| ('marketing', '2025-05-23 10:30:00', '2025-05-23 14:30:00', 4), | ||
| ('crypto-event', '2025-05-26 11:00:00', '2025-05-26 15:00:00', 5); | ||
|
|
||
| `; | ||
| connection.connect((err) => { | ||
| if (err) throw err; | ||
| console.log("connected to mysql"); | ||
|
|
||
| connection.query(setUpQueries, (err) => { | ||
| if (err) throw err; | ||
| console.log("databese and tables and data been inserted "); | ||
| connection.end(); | ||
| }); | ||
| }); | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,37 @@ | ||
| import mysql from "mysql2"; | ||
| const connection = mysql.createConnection({ | ||
| host: "localhost", | ||
| user: "hyfuser", | ||
| password: "hyfpassword", | ||
| database: "new_world", | ||
| }); | ||
| connection.connect((err) => { | ||
| if (err) throw err; | ||
| console.log(" Connected to new_world database"); | ||
|
|
||
| const queries = [ | ||
| "select name from country where Population > 8000000", | ||
| "SELECT name FROM country WHERE name LIKE '%land%'", | ||
| "select name from city where population between 500000 and 1000000", | ||
| "SeLect Name FROM country WHERE Continent = 'Europe'", | ||
| "SELECT Name, SurfaceArea FROM country ORDER BY SurfaceArea DESC", | ||
| 'select name from city where countrycode = "nld" ', | ||
| 'select population from city where name = "rotterdam" ', | ||
| "select name, surfacearea from country order by surfacearea desc limit 10", | ||
| "select name, population from city order by population desc limit 10", | ||
| "select sum (population) as wrold_population from country", | ||
| ]; | ||
|
|
||
| queries.forEach((query, index) => { | ||
| connection.query(query, (err, results) => { | ||
| if (err) throw err; | ||
| console.log(`${index + 1}:`); | ||
| console.table(results); | ||
| }); | ||
| }); | ||
|
|
||
| setTimeout(() => { | ||
| connection.end(); | ||
| console.log("Done running all queries"); | ||
| }, 1500); | ||
| }); |
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.
Nice use of foreign key!