From e9e8f07615504b4b78233ddcd81dc477da3d86bf Mon Sep 17 00:00:00 2001 From: Rohini Patil Date: Thu, 25 Sep 2025 12:19:18 +0200 Subject: [PATCH] Revert "Hanna_Dubyna-w1-Databases" --- Week1/scripts/databasepg.js | 118 --------------------------------- Week1/scripts/world-queries.js | 80 ---------------------- 2 files changed, 198 deletions(-) delete mode 100644 Week1/scripts/databasepg.js delete mode 100644 Week1/scripts/world-queries.js diff --git a/Week1/scripts/databasepg.js b/Week1/scripts/databasepg.js deleted file mode 100644 index 946dd6e4d..000000000 --- a/Week1/scripts/databasepg.js +++ /dev/null @@ -1,118 +0,0 @@ -import { Client } from "pg"; - -const client = new Client({ - host: "localhost", - user: "hyfuser", - port: 5432, - password: "hyfpassword", - database: "meetup", -}); - -async function initializeDatabase() { - try { - await client.connect(); - console.log("Connected to PostgresQL"); - - await client.query(` - CREATE TABLE IF NOT EXISTS Invitee( - invitee_no SERIAL PRIMARY KEY, - invitee_name VARCHAR(100), - invited_by VARCHAR(100) - )`); - - // Remove all rows before inserting new data to avoid duplicates - await client.query(`DELETE FROM Meeting;`); - await client.query(`DELETE FROM Room;`); - await client.query(`DELETE FROM Invitee;`); - - // Reset sequences so IDs start from 1 - await client.query(`ALTER SEQUENCE invitee_invitee_no_seq RESTART WITH 1;`); - await client.query(`ALTER SEQUENCE room_room_no_seq RESTART WITH 1;`); - await client.query(`ALTER SEQUENCE meeting_meeting_no_seq RESTART WITH 1;`); - - await client.query(` - CREATE TABLE IF NOT EXISTS Room( - room_no SERIAL PRIMARY KEY, - room_name VARCHAR(100), - floor_number INTEGER - ) `); - - await client.query(`DELETE FROM Room;`); - - await client.query(` - CREATE TABLE IF NOT EXISTS Meeting( - meeting_no SERIAL PRIMARY KEY, - meeting_title VARCHAR(100), - starting_time TIMESTAMP, - ending_time TIMESTAMP, - room_no INTEGER REFERENCES Room(room_no) - ) - `); - - await client.query(` - INSERT INTO Invitee (invitee_name, invited_by) VALUES - ('Scarlett Johansson', 'Aiden Cross'), - ('Leonardo DiCaprio', 'Lila Montgomery'), - ('Taylor Swift', 'Ethan Caldwell'), - ('Chris Hemsworth', 'Sophia Bennett'), - ('Emma Watson', 'Jackson Rivers') - `); - - await client.query(` - INSERT INTO Room(room_name, floor_number) VALUES - ('black room', 2), - ('white room', 3), - ('silver room', 4), - ('black room', 2), - ('golden room', 1) - `); - - const rooms = await client.query(`SELECT room_no FROM Room`); - const roomIds = rooms.rows.map((r) => r.room_no); - - const meetingsData = [ - { - title: "Kickoff", - start: "2025-08-27 10:00:00", - end: "2025-08-27 12:00:00", - }, - { - title: "Planning Session", - start: "2025-08-27 13:00:00", - end: "2025-08-27 14:00:00", - }, - { - title: "Team Meeting", - start: "2025-08-27 14:30:00", - end: "2025-08-27 15:30:00", - }, - { - title: "Retrospective", - start: "2025-08-27 16:00:00", - end: "2025-08-27 17:00:00", - }, - { - title: "Client Presentation", - start: "2025-08-27 17:30:00", - end: "2025-08-27 18:00:00", - }, - ]; - - for (const m of meetingsData) { - const randomRoom = roomIds[Math.floor(Math.random() * roomIds.length)]; - await client.query( - `INSERT INTO Meeting(meeting_title, starting_time, ending_time, room_no) - VALUES ($1, $2, $3, $4)`, - [m.title, m.start, m.end, randomRoom] - ); - } - - console.log("Tables Invitee, Room, and Meeting created and populated!"); - } catch (err) { - console.error("Error:", err); - } finally { - await client.end(); - } -} - -initializeDatabase(); diff --git a/Week1/scripts/world-queries.js b/Week1/scripts/world-queries.js deleted file mode 100644 index 282eb596f..000000000 --- a/Week1/scripts/world-queries.js +++ /dev/null @@ -1,80 +0,0 @@ -import { Client } from "pg"; - -const client = new Client({ - host: "localhost", - user: "hyfuser", - port: 5432, - password: "hyfpassword", - database: "world", -}); - -async function runWorldQueries() { - try { - await client.connect(); - console.log("Connected to PostgressQL!"); - - await client.query(` - SELECT country.name FROM country -WHERE country.population > 8000000 - `); - - await client.query(` - SELECT country.name FROM country - WHERE country.name LIKE '%land%' - `); - - await client.query(` - SELECT city.name FROM city - WHERE city.population >= 500000 AND city.population <= 1000000 - `); - - await client.query(` - SELECT country.name FROM country - WHERE country.continent = 'Europe' - `); - - await client.query(` - SELECT * FROM country ORDER BY - surfacearea DESC - `); - - await client.query(` - SELECT city.name - FROM city - JOIN country ON city.countrycode = country.code - WHERE country.name = 'Netherlands' - `); - - await client.query(` - SELECT population - FROM city - WHERE name = 'Rotterdam' - `); - - await client.query(` - SELECT name, surfacearea - FROM country - ORDER BY - surfacearea DESC - LIMIT 10 - `); - - await client.query(` - SELECT name, population - FROM city - ORDER BY population DESC - LIMIT 10 - `); - - await client.query(` - SELECT SUM(population) AS world_population - FROM country - `); - } catch (err) { - console.error("Error:", err); - } finally { - await client.end(); - } -} - -runWorldQueries();