From 4b905c08cd041abd4ab7a3f8c25cfaf84b207d66 Mon Sep 17 00:00:00 2001 From: Rohini Patil Date: Thu, 25 Sep 2025 12:20:41 +0200 Subject: [PATCH] Revert "Yahya Al-Ademi -w2-databases" --- Week2/assignment database-week2/.gitignore | 14 -- .../exercise1-keys/exercise1_keys.js | 48 ------ .../exercise2-Relationships/data.js | 89 ---------- .../exercise2_Relationships.js | 51 ------ .../exercise3-Joins/exercise3-Joins.js | 49 ------ .../query_Aggregate_Functions.js | 83 --------- .../package-lock.json | 162 ------------------ Week2/assignment database-week2/package.json | 15 -- 8 files changed, 511 deletions(-) delete mode 100644 Week2/assignment database-week2/.gitignore delete mode 100644 Week2/assignment database-week2/exercise1-keys/exercise1_keys.js delete mode 100644 Week2/assignment database-week2/exercise2-Relationships/data.js delete mode 100644 Week2/assignment database-week2/exercise2-Relationships/exercise2_Relationships.js delete mode 100644 Week2/assignment database-week2/exercise3-Joins/exercise3-Joins.js delete mode 100644 Week2/assignment database-week2/exercise4- Aggregate Functions/query_Aggregate_Functions.js delete mode 100644 Week2/assignment database-week2/package-lock.json delete mode 100644 Week2/assignment database-week2/package.json diff --git a/Week2/assignment database-week2/.gitignore b/Week2/assignment database-week2/.gitignore deleted file mode 100644 index d69fccb74..000000000 --- a/Week2/assignment database-week2/.gitignore +++ /dev/null @@ -1,14 +0,0 @@ -# Node.js dependencies -node_modules/ - - -# OS-specific files -.DS_Store -Thumbs.db - -# Editor folders/files -.vscode/ -.idea/ -*.swp - - diff --git a/Week2/assignment database-week2/exercise1-keys/exercise1_keys.js b/Week2/assignment database-week2/exercise1-keys/exercise1_keys.js deleted file mode 100644 index 8e53d7a4d..000000000 --- a/Week2/assignment database-week2/exercise1-keys/exercise1_keys.js +++ /dev/null @@ -1,48 +0,0 @@ -import { Pool } from "pg"; - -const pool = new Pool({ - host: "localhost", - user: "hyfuser", - password: "hyfpassword", - database: "authors_db", - port: 5432, -}); - -async function main() { - try { - await pool.query("DROP TABLE IF EXISTS authors"); - console.log("Table dropped successfully"); - const queryText = ` - CREATE TABLE authors ( - author_id SERIAL PRIMARY KEY, - author_name VARCHAR(50)NOT NULL, - university VARCHAR(100) NOT NULL, - date_of_birth DATE, - h_index INT, - gender VARCHAR(10) NOT NULL CHECK(gender in('Male', 'Female')) -); -`; - await pool.query(queryText); - console.log("Table Successfully created"); - - await pool.query(` - ALTER TABLE authors - ADD COLUMN mentor INT; - `); - console.log("Column mentor added successfully"); - - await pool.query(` - ALTER TABLE authors - ADD CONSTRAINT fk_mentor - Foreign Key (mentor) REFERENCES authors(author_id); - `); - console.log("Foreign key fk_mentor added successfully"); - - - } catch (error) { - console.error("Error", error); - } finally { - await pool.end(); - } -} -main(); diff --git a/Week2/assignment database-week2/exercise2-Relationships/data.js b/Week2/assignment database-week2/exercise2-Relationships/data.js deleted file mode 100644 index a24e80e3f..000000000 --- a/Week2/assignment database-week2/exercise2-Relationships/data.js +++ /dev/null @@ -1,89 +0,0 @@ -import { Pool } from "pg"; - -const pool = new Pool({ - host: "localhost", - user: "hyfuser", - password: "hyfpassword", - database: "authors_db", - port: 5432, -}); - -async function insertData() { - try { - - await pool.query(` - INSERT INTO authors (author_name, university, date_of_birth, h_index, gender, mentor) - VALUES - ('Aref Al-Ademi', 'Al-Mansoori University', '1980-05-10', 25, 'Male', 14), - ('Sara Ali', 'Cairo University', '1985-02-20', 30, 'Female', 1), - ('John Smith', 'MIT', '1975-11-15', 40, 'Male', 1), - ('Jane Doe', 'Stanford', '1982-07-30', 35, 'Female', 2), - ('Author 5', 'University 5', '1981-01-01', 20, 'Male', 3), - ('Author 6', 'University 6', '1983-03-12', 22, 'Female', 4), - ('Author 7', 'University 7', '1979-12-05', 18, 'Male', 5), - ('Author 8', 'University 8', '1986-06-17', 28, 'Female', 6), - ('Author 9', 'University 9', '1980-09-21', 25, 'Male', 7), - ('Author 10', 'University 10', '1984-04-10', 30, 'Female', 8), - ('Author 11', 'University 11', '1978-08-08', 19, 'Male', 9), - ('Author 12', 'University 12', '1987-03-25', 27, 'Female', 10), - ('Author 13', 'University 13', '1981-10-11', 24, 'Male', 11), - ('Author 14', 'University 14', '1985-12-19', 32, 'Female', 12), - ('Author 15', 'University 15', '1982-01-05', 26, 'Male', 13) - ON CONFLICT DO NOTHING - `); - - await pool.query(` - INSERT INTO research_papers (paper_title, conference, publish_date) - VALUES - ('Paper 1', 'Conf A', '2020-01-10'), - ('Paper 2', 'Conf B', '2020-03-15'), - ('Paper 3', 'Conf C', '2019-07-20'), - ('Paper 4', 'Conf D', '2021-02-11'), - ('Paper 5', 'Conf E', '2018-06-30'), - ('Paper 6', 'Conf F', '2020-11-05'), - ('Paper 7', 'Conf G', '2019-09-19'), - ('Paper 8', 'Conf H', '2021-01-22'), - ('Paper 9', 'Conf I', '2020-05-14'), - ('Paper 10', 'Conf J', '2021-08-30'), - ('Paper 11', 'Conf A', '2019-04-10'), - ('Paper 12', 'Conf B', '2020-12-01'), - ('Paper 13', 'Conf C', '2018-07-18'), - ('Paper 14', 'Conf D', '2021-03-11'), - ('Paper 15', 'Conf E', '2020-06-22'), - ('Paper 16', 'Conf F', '2019-11-05'), - ('Paper 17', 'Conf G', '2021-02-19'), - ('Paper 18', 'Conf H', '2020-01-22'), - ('Paper 19', 'Conf I', '2019-05-14'), - ('Paper 20', 'Conf J', '2021-08-30'), - ('Paper 21', 'Conf A', '2020-02-10'), - ('Paper 22', 'Conf B', '2019-03-15'), - ('Paper 23', 'Conf C', '2021-07-20'), - ('Paper 24', 'Conf D', '2020-02-11'), - ('Paper 25', 'Conf E', '2018-06-30'), - ('Paper 26', 'Conf F', '2020-11-05'), - ('Paper 27', 'Conf G', '2019-09-19'), - ('Paper 28', 'Conf H', '2021-01-22'), - ('Paper 29', 'Conf I', '2020-05-14'), - ('Paper 30', 'Conf J', '2021-08-30') - ON CONFLICT DO NOTHING - `); - await pool.query(` - INSERT INTO authors_papers (author_id, paper_id) - VALUES - (1,1),(1,2),(2,3),(2,4),(3,5),(3,6), - (4,7),(4,8),(5,9),(5,10),(6,11),(6,12), - (7,13),(7,14),(8,15),(8,16),(9,17),(9,18), - (10,19),(10,20),(11,21),(11,22),(12,23),(12,24), - (13,25),(13,26),(14,27),(14,28),(15,29),(15,30) - ON CONFLICT DO NOTHING - `); - - console.log("Data insertion completed successfully!"); - } catch (err) { - console.error(err); - } finally { - await pool.end(); - } -} - -insertData(); diff --git a/Week2/assignment database-week2/exercise2-Relationships/exercise2_Relationships.js b/Week2/assignment database-week2/exercise2-Relationships/exercise2_Relationships.js deleted file mode 100644 index 38a8bf66f..000000000 --- a/Week2/assignment database-week2/exercise2-Relationships/exercise2_Relationships.js +++ /dev/null @@ -1,51 +0,0 @@ -import { Pool } from "pg"; - -const pool = new Pool({ - host: "localhost", - user: "hyfuser", - password: "hyfpassword", - database: "authors_db", - port: 5432, -}); - -async function main() { - try { - - - await pool.query("DROP TABLE IF EXISTS authors_papers"); - await pool.query("DROP TABLE IF EXISTS research_Papers"); - console.log("Tables dropped successfully"); - - const createResearchPapers = ` - CREATE TABLE research_Papers ( - paper_id SERIAL PRIMARY KEY, - paper_title VARCHAR(50)NOT NULL, - conference VARCHAR(100) NOT NULL, - publish_date DATE -); -`; - await pool.query(createResearchPapers); - console.log("Table Successfully created"); - - const createAuthorsPapers = ` - CREATE TABLE authors_papers ( - author_id INT, - paper_id INT, - PRIMARY KEY(author_id, paper_id), - Foreign Key (author_id ) REFERENCES authors(author_id), - Foreign Key (paper_id) REFERENCES research_Papers(paper_id) -); -`; -await pool.query(createAuthorsPapers); -console.log("Injection table Successfully created"); - - - - - } catch (error) { - console.error("Error", error); - } finally { - await pool.end(); - } -} -main(); diff --git a/Week2/assignment database-week2/exercise3-Joins/exercise3-Joins.js b/Week2/assignment database-week2/exercise3-Joins/exercise3-Joins.js deleted file mode 100644 index be3a404f4..000000000 --- a/Week2/assignment database-week2/exercise3-Joins/exercise3-Joins.js +++ /dev/null @@ -1,49 +0,0 @@ -import { Pool } from "pg"; - -const pool = new Pool({ - host: "localhost", - user: "hyfuser", - password: "hyfpassword", - database: "authors_db", - port: 5432, -}); - -async function main() { - try { - const reuslt = await pool.query(`SELECT - authors.author_name AS author, - mentors.author_name AS mentor - FROM - authors - LEFT JOIN - authors AS mentors - ON - authors.mentor = mentors.author_id; - `); - console.log("Authors and their mentors:"); - console.table(reuslt.rows); - - const reuslt2 = await pool.query(`SELECT - authors.*, - research_Papers.paper_title - FROM - authors - LEFT JOIN - authors_papers - ON - authors.author_id = authors_papers.author_id - LEFT JOIN - research_Papers - ON - authors_papers.paper_id = research_Papers.paper_id; - `); - console.log("Authors and their papers:"); - console.table(reuslt2.rows); - - } catch (error) { - console.error("Error", error); - } finally { - await pool.end(); - } -} -main(); diff --git a/Week2/assignment database-week2/exercise4- Aggregate Functions/query_Aggregate_Functions.js b/Week2/assignment database-week2/exercise4- Aggregate Functions/query_Aggregate_Functions.js deleted file mode 100644 index ce98dac91..000000000 --- a/Week2/assignment database-week2/exercise4- Aggregate Functions/query_Aggregate_Functions.js +++ /dev/null @@ -1,83 +0,0 @@ -import { Pool } from "pg"; - -const pool = new Pool({ - host: "localhost", - user: "hyfuser", - password: "hyfpassword", - database: "authors_db", - port: 5432, -}); - -async function main() { - try { - const reuslt= await pool.query("SELECT * FROM authors") - console.log("\n=== AUTHORS ==="); - console.table(reuslt.rows) - - const reuslt1= await pool.query("SELECT * FROM research_Papers") - console.log("\n=== RESEARCH PAPERS ==="); - console.table(reuslt1.rows) - - const reuslt2= await pool.query("SELECT * FROM authors_papers") - console.log("\n=== AUTHORS PAPERS ==="); - console.table(reuslt2.rows) - - const res = await pool.query(` - SELECT - research_papers.paper_title AS A_research_paper, - COUNT(authors_papers.author_id) AS number_of_authors - FROM research_papers - LEFT JOIN authors_papers ON research_papers.paper_id = authors_papers.paper_id - GROUP BY research_papers.paper_id, research_papers.paper_title - ORDER BY research_papers.paper_id - `); - console.table(res.rows); - - const res1 = await pool.query(` - SELECT - COUNT(authors_papers.paper_id) AS total_papers_female_authors - FROM authors - JOIN authors_papers ON authors.author_id = authors_papers.author_id - WHERE authors.gender = 'Female' - `); - console.table(res1.rows); - - const res2 = await pool.query(` - SELECT - authors.university, - AVG(authors.h_index) AS avg_h_index - FROM authors - GROUP BY authors.university - ORDER BY authors.university - `); - console.table(res2.rows); - - const res3 = await pool.query(` - SELECT - authors.university, - COUNT(authors_papers.paper_id) AS total_papers - FROM authors - LEFT JOIN authors_papers ON authors.author_id = authors_papers.author_id - GROUP BY authors.university - ORDER BY authors.university - `); - - console.table(res3.rows); - - const res4 = await pool.query(` - SELECT - authors.university, - MIN(authors.h_index) AS min_h_index, - MAX(authors.h_index) AS max_h_index - FROM authors - GROUP BY authors.university - ORDER BY authors.university - `); - console.table(res4.rows); - } catch (error) { - console.error("Error", error); - } finally { - await pool.end(); - } -} -main(); diff --git a/Week2/assignment database-week2/package-lock.json b/Week2/assignment database-week2/package-lock.json deleted file mode 100644 index c0c4fcd7a..000000000 --- a/Week2/assignment database-week2/package-lock.json +++ /dev/null @@ -1,162 +0,0 @@ -{ - "name": "assignment-database-week2", - "version": "1.0.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "assignment-database-week2", - "version": "1.0.0", - "license": "ISC", - "dependencies": { - "pg": "^8.16.3" - } - }, - "node_modules/pg": { - "version": "8.16.3", - "resolved": "https://registry.npmjs.org/pg/-/pg-8.16.3.tgz", - "integrity": "sha512-enxc1h0jA/aq5oSDMvqyW3q89ra6XIIDZgCX9vkMrnz5DFTw/Ny3Li2lFQ+pt3L6MCgm/5o2o8HW9hiJji+xvw==", - "license": "MIT", - "dependencies": { - "pg-connection-string": "^2.9.1", - "pg-pool": "^3.10.1", - "pg-protocol": "^1.10.3", - "pg-types": "2.2.0", - "pgpass": "1.0.5" - }, - "engines": { - "node": ">= 16.0.0" - }, - "optionalDependencies": { - "pg-cloudflare": "^1.2.7" - }, - "peerDependencies": { - "pg-native": ">=3.0.1" - }, - "peerDependenciesMeta": { - "pg-native": { - "optional": true - } - } - }, - "node_modules/pg-cloudflare": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/pg-cloudflare/-/pg-cloudflare-1.2.7.tgz", - "integrity": "sha512-YgCtzMH0ptvZJslLM1ffsY4EuGaU0cx4XSdXLRFae8bPP4dS5xL1tNB3k2o/N64cHJpwU7dxKli/nZ2lUa5fLg==", - "license": "MIT", - "optional": true - }, - "node_modules/pg-connection-string": { - "version": "2.9.1", - "resolved": "https://registry.npmjs.org/pg-connection-string/-/pg-connection-string-2.9.1.tgz", - "integrity": "sha512-nkc6NpDcvPVpZXxrreI/FOtX3XemeLl8E0qFr6F2Lrm/I8WOnaWNhIPK2Z7OHpw7gh5XJThi6j6ppgNoaT1w4w==", - "license": "MIT" - }, - "node_modules/pg-int8": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", - "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw==", - "license": "ISC", - "engines": { - "node": ">=4.0.0" - } - }, - "node_modules/pg-pool": { - "version": "3.10.1", - "resolved": "https://registry.npmjs.org/pg-pool/-/pg-pool-3.10.1.tgz", - "integrity": "sha512-Tu8jMlcX+9d8+QVzKIvM/uJtp07PKr82IUOYEphaWcoBhIYkoHpLXN3qO59nAI11ripznDsEzEv8nUxBVWajGg==", - "license": "MIT", - "peerDependencies": { - "pg": ">=8.0" - } - }, - "node_modules/pg-protocol": { - "version": "1.10.3", - "resolved": "https://registry.npmjs.org/pg-protocol/-/pg-protocol-1.10.3.tgz", - "integrity": "sha512-6DIBgBQaTKDJyxnXaLiLR8wBpQQcGWuAESkRBX/t6OwA8YsqP+iVSiond2EDy6Y/dsGk8rh/jtax3js5NeV7JQ==", - "license": "MIT" - }, - "node_modules/pg-types": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/pg-types/-/pg-types-2.2.0.tgz", - "integrity": "sha512-qTAAlrEsl8s4OiEQY69wDvcMIdQN6wdz5ojQiOy6YRMuynxenON0O5oCpJI6lshc6scgAY8qvJ2On/p+CXY0GA==", - "license": "MIT", - "dependencies": { - "pg-int8": "1.0.1", - "postgres-array": "~2.0.0", - "postgres-bytea": "~1.0.0", - "postgres-date": "~1.0.4", - "postgres-interval": "^1.1.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/pgpass": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/pgpass/-/pgpass-1.0.5.tgz", - "integrity": "sha512-FdW9r/jQZhSeohs1Z3sI1yxFQNFvMcnmfuj4WBMUTxOrAyLMaTcE1aAMBiTlbMNaXvBCQuVi0R7hd8udDSP7ug==", - "license": "MIT", - "dependencies": { - "split2": "^4.1.0" - } - }, - "node_modules/postgres-array": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/postgres-array/-/postgres-array-2.0.0.tgz", - "integrity": "sha512-VpZrUqU5A69eQyW2c5CA1jtLecCsN2U/bD6VilrFDWq5+5UIEVO7nazS3TEcHf1zuPYO/sqGvUvW62g86RXZuA==", - "license": "MIT", - "engines": { - "node": ">=4" - } - }, - "node_modules/postgres-bytea": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/postgres-bytea/-/postgres-bytea-1.0.0.tgz", - "integrity": "sha512-xy3pmLuQqRBZBXDULy7KbaitYqLcmxigw14Q5sj8QBVLqEwXfeybIKVWiqAXTlcvdvb0+xkOtDbfQMOf4lST1w==", - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/postgres-date": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/postgres-date/-/postgres-date-1.0.7.tgz", - "integrity": "sha512-suDmjLVQg78nMK2UZ454hAG+OAW+HQPZ6n++TNDUX+L0+uUlLywnoxJKDou51Zm+zTCjrCl0Nq6J9C5hP9vK/Q==", - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/postgres-interval": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/postgres-interval/-/postgres-interval-1.2.0.tgz", - "integrity": "sha512-9ZhXKM/rw350N1ovuWHbGxnGh/SNJ4cnxHiM0rxE4VN41wsg8P8zWn9hv/buK00RP4WvlOyr/RBDiptyxVbkZQ==", - "license": "MIT", - "dependencies": { - "xtend": "^4.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/split2": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/split2/-/split2-4.2.0.tgz", - "integrity": "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg==", - "license": "ISC", - "engines": { - "node": ">= 10.x" - } - }, - "node_modules/xtend": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", - "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", - "license": "MIT", - "engines": { - "node": ">=0.4" - } - } - } -} diff --git a/Week2/assignment database-week2/package.json b/Week2/assignment database-week2/package.json deleted file mode 100644 index d15cf8358..000000000 --- a/Week2/assignment database-week2/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "assignment-database-week2", - "version": "1.0.0", - "description": "", - "main": "data.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "keywords": [], - "author": "", - "license": "ISC", - "dependencies": { - "pg": "^8.16.3" - } -}