Skip to content

Commit cd6af1a

Browse files
done
1 parent 0159d62 commit cd6af1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1117
-1
lines changed

.env.example

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONNECT_TO_MONGODB

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_store
2+
.venv
3+
.env

MongoDB_CLI/main.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os
2+
3+
# Accessing environment variables and connect to MongoDB
4+
connect = os.getenv("CONNECT_TO_MONGODB")
5+
6+
# Create a new folder collection in the database:
7+
command = 'db.createCollection("trees")'
8+
9+
10+
# Insert a new document into the collection:
11+
command = """db.trees.insertOne({
12+
"name": "Trees",
13+
"description": "Collection of information about trees",
14+
"contents": ["Oak", "Maple", "Pine", "Birch"]
15+
})"""
16+
17+
# Insert documents for trees with properties
18+
command = """db.trees.insertMany([
19+
{"name": "Oak", "age": 50, "features": ["tall", "strong wood"]},
20+
{"name": "Maple", "age": 40, "features": ["colorful leaves", "syrup production"]},
21+
{"name": "Pine", "age": 30, "features": ["evergreen", "pine cones"]},
22+
{"name": "Birch", "age": 35, "features": ["distinct bark", "graceful appearance"]}
23+
])"""
24+
25+
26+
# Find a tree document by its name:
27+
command = 'db.trees.findOne({"name": "Oak"})'
28+
29+
# Find all documents in the collection:
30+
command = "db.trees.find({})"
31+
32+
# Update the age of a tree document:
33+
command = 'db.trees.updateOne({"name": "Oak"}, {"$set": {"age": 50}})'
34+
35+
# Add a new feature to the list of features for a tree by its name:
36+
command = 'db.trees.updateOne({"name": "Oak"}, {"$push": {"features": "thrives in acidic soil"}})'
37+
38+
# Delete a tree document by its name:
39+
command = 'db.trees.deleteOne({"name": "Oak"})'
40+
41+
# Delete all documents from a collection:
42+
command = "db.trees.deleteMany({})"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-- INSERT INTO tasks (title, description, status_id, user_id) VALUES ('New Task', 'Task Description', <status_id>, <user_id>);
2+
3+
INSERT INTO tasks (title, description, status_id, user_id) VALUES ('Wash the dish', 'Take it, wash it, dry it', 2, 4);
4+
5+
6+
-- id|title |description |status_id|user_id|
7+
-- --+-------------+-------------------------+---------+-------+
8+
-- 21|Wash the dish|Take it, wash it, dry it | 2| 4|

PostgreSQL/SQL_commands/add/user.sql

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
INSERT INTO users (id, fullName, email) VALUES ('11', 'Tory Drake', 'torydrake@example.com ');
2+
3+
-- id|fullName |email |
4+
-- --+----------------+-------------------------+
5+
-- 3|Steven Jacobs |robertcruz@example.net |
6+
-- 5|Gabriel Kent |tracymorgan@example.com |
7+
-- 6|Jimmy Cross |thompsonbrian@example.net|
8+
-- 7|Blake Miller DDS|lewiseric@example.net |
9+
-- 8|Jeffrey Fisher |mathew72@example.net |
10+
-- 9|John Downs |matthew53@example.org |
11+
-- 4|John Green |davidtaylor@example.com |
12+
-- 1|Mike Cook |bryantteresa@example.org |
13+
-- 10|Emily Rose |juliehoward@example.net |
14+
-- 11|Tory Drake |torydrake@example.com |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
CREATE TABLE status (
2+
id SERIAL PRIMARY KEY,
3+
name VARCHAR(50) UNIQUE,
4+
CONSTRAINT valid_status_name CHECK (name IN ('new', 'in progress', 'completed'))
5+
);
6+
7+
8+
-- id|name |
9+
-- --+-----------+
10+
-- 1|new |
11+
-- 2|in progress|
12+
-- 3|completed |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
CREATE TABLE tasks (
2+
id SERIAL PRIMARY KEY,
3+
title VARCHAR(100),
4+
description TEXT,
5+
status_id INTEGER,
6+
user_id INTEGER,
7+
FOREIGN KEY (status_id) REFERENCES status(id),
8+
FOREIGN KEY (user_id) REFERENCES users(id)
9+
);
10+
11+
12+
-- id|title |description |status_id|user_id|
13+
-- --+---------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------+-------+
14+
-- 1|Speak new fact board difference executive. |Good share doctor home policy feeling pressure. Animal huge benefit may career section.¶Research force along finally above local already. | 3| 1|
15+
-- 2|Decision wide before loss. |Before price society simply plant debate smile. Money baby hotel forward particular worry contain.¶Scientist stop director strong. Card painting respond develop hour. | 1| 2|
16+
-- 3|Message western year him keep. |First each describe weight. Other level physical test. Activity become clearly help life employee a your. | 2| 5|
17+
-- 4|Evidence turn the recognize reason. |Study military end political cost. Identify loss company explain white. Someone describe simply during some television recently. | 1| 5|
18+
-- 5|Miss wall magazine. |Six alone include along. Show similar build range defense action. Throughout feeling hair seven pay long feel.¶Collection may fine onto recently hear spend. Thought few research available today yes.| 2| 1|
19+
-- 6|Prove major method mouth. |Him eye accept language. Nature student organization floor do discuss. Series relationship culture drive successful change off tax.¶Until short quite message top area fund. Glass group expert wish. | 1| 1|
20+
-- 7|Fire suggest to thus old she oil would. |Discover page fall official thank entire yet. Shoulder nature third their concern guy study leave. Strong ground small past though. | 1| 4|
21+
-- 8|Beyond short hold future within. |Draw others fight scene size.¶As send stuff drop black sort political. Hospital not arm need how meet upon here. | 2| 6|
22+
-- 9|Mention behind full hundred thousand mention.|Discussion from view section risk. Good build husband rich arm.¶Food care popular discover. Author follow school true drive smile. | 2| 1|
23+
-- 10|Visit standard pretty. |Often make water. Choice art building piece certain break even participant. Size bit best possible instead tend.¶Difficult hope good employee quickly technology catch. No read particularly. | 1| 5|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CREATE TABLE users (
2+
id SERIAL PRIMARY KEY,
3+
fullName VARCHAR(100),
4+
email VARCHAR(100) UNIQUE
5+
);
6+
7+
-- id|fullName |email |
8+
-- --+----------------+----------------------------+
9+
-- 1|Elizabeth Patton|alexandra80@example.net |
10+
-- 2|Rodney Craig |pjohnson@example.net |
11+
-- 3|Paul Daniel |xjohnson@example.org |
12+
-- 4|Amanda Parks |clintongraham@example.com |
13+
-- 5|Joseph Patterson|yhoward@example.org |
14+
-- 6|Timothy Jimenez |davenportdorothy@example.net|
15+
-- 7|James Moreno |lukeroberts@example.org |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- Step 1: Disable foreign key constraints
2+
-- This SQL script disables foreign key constraints for all tables in the database
3+
DO $$ DECLARE
4+
r record;
5+
BEGIN
6+
FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP
7+
EXECUTE 'ALTER TABLE ' || quote_ident(r.tablename) || ' DISABLE TRIGGER ALL';
8+
END LOOP;
9+
END $$;
10+
11+
-- Step 2: Drop all tables
12+
-- This SQL script drops all tables in the database
13+
DO $$ DECLARE
14+
r record;
15+
BEGIN
16+
FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP
17+
EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.tablename) || ' CASCADE';
18+
END LOOP;
19+
END $$;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ALTER TABLE tasks
2+
DROP CONSTRAINT tasks_user_id_fkey;
3+
4+
ALTER TABLE tasks
5+
ADD CONSTRAINT tasks_user_id_fkey
6+
FOREIGN KEY (user_id)
7+
REFERENCES users(id)
8+
ON DELETE CASCADE;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
-- DELETE FROM tasks WHERE id = <task_id>;
2+
3+
DELETE FROM tasks WHERE id = 12;
4+
DELETE FROM tasks WHERE id = 17;
5+
DELETE FROM tasks WHERE id = 19;
6+
7+
-- id|title |description |status_id|user_id|
8+
-- --+-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------+-------+
9+
-- 1|Together herself hotel word may leader should. |Television they vote adult teach. Include life crime.¶Interesting have include Mr. Run program reality dark manager blood way along.¶Goal miss decide wall smile enjoy it. Talk interesting shake. | 1| 10|
10+
-- 3|Within young near huge help happy. |Sometimes second scientist production rest friend. Read door out will. Five even important house energy.¶Threat social ago ground important lose.¶Business build look. Off stay east we including this.| 1| 6|
11+
-- 4|State than decide modern real add. |Buy tonight couple born. Must certain but. Agency usually option buy property fall success. | 1| 10|
12+
-- 5|Money toward image him ball gun. |The must PM then owner none number. Food expect with position.¶Stand land accept course include generation in yet. Truth probably just thing degree inside scientist some. | 1| 1|
13+
-- 6|Different law expert. Think someone street above.|Blood reflect old success. Our pull site.¶Inside their threat glass. There either team. Level power growth difficult cost general. | 1| 7|
14+
-- 8|Range great detail always. |Yeah become computer. Value think performance drive name. Especially toward agree walk moment firm American many. | 2| 7|
15+
-- 9|Radio side wish guy hit memory. |Organization window military development day. Them such protect kitchen employee film answer. Yeah natural its. | 1| 3|
16+
-- 11|Ready affect whatever develop discover. |Capital security quickly perhaps stand wife. Follow attorney form seven. Discover rock when.¶Despite mention else bar talk. Admit manage test which gun. Head follow have seem. | 3| 1|
17+
-- 13|My radio section enjoy technology. |Positive fish decade mission. Easy study paper. Show especially week mind could. | 1| 7|
18+
-- 14|Must score area real alone growth plan claim. |Bed difficult front voice. Statement can Congress painting sit.¶Vote wall it. Happen social glass small keep but keep cost. | 2| 7|
19+
-- 15|Hold game per threat avoid color wait. |Identify there group thing school whose station. Assume college little offer stock before down. | 3| 2|
20+
-- 16|Reduce American whom bring marriage. |Major another study research. Hour health road last.¶Budget bad point consider. Agreement value will discussion course site want. Evidence hope team executive side southern hair. | 1| 7|
21+
-- 18|True cause once wall authority impact. |Ability that side mention well his. Present less especially drop season general bed.¶Difficult western old media. However response administration letter challenge participant. Radio focus each. | 1| 1|
22+
-- 20|Let spring also reveal every. Present get put. |Often might us organization coach world than. Newspaper least traditional case. Discover stand chair hospital head. | 1| 8|
23+
-- 7|Police cause participant. |Especially every sort relationship me inside. Thing government eight. Now state wind trouble hit then four.¶Speech off always authority. | 3| 10|
24+
-- 10|Difficult almost foreign hit carry past first. |Site long whatever. Peace enough effort. Finish rather wind watch ready.¶Particular four side address reflect degree enjoy. | 3| 10|
25+
-- 21|Wash the dish |Take it, wash it, dry it | 2| 4|
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
ALTER TABLE tasks
2+
ADD CONSTRAINT status_user_id_fkey
3+
FOREIGN KEY (status_id)
4+
REFERENCES status(id)
5+
ON DELETE CASCADE;
6+
7+
-- Step 1: Drop foreign key constraints referencing the status table
8+
-- Assuming there are foreign key constraints in the tasks table referencing the status_id column of the status table
9+
-- ALTER TABLE tasks DROP CONSTRAINT status_id;
10+
11+
-- Step 2: Delete data from related tables
12+
-- Assuming the tasks table has a status_id column referencing the id column of the status table
13+
DELETE FROM tasks WHERE status_id IN (SELECT id FROM status);
14+
15+
-- Step 3: Drop the status table
16+
DROP TABLE status CASCADE;
17+
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
DELETE FROM users WHERE id = 2;
2+
3+
-- id|fullName |email |
4+
-- --+----------------+-------------------------+
5+
-- 3|Steven Jacobs |robertcruz@example.net |
6+
-- 5|Gabriel Kent |tracymorgan@example.com |
7+
-- 6|Jimmy Cross |thompsonbrian@example.net|
8+
-- 7|Blake Miller DDS|lewiseric@example.net |
9+
-- 8|Jeffrey Fisher |mathew72@example.net |
10+
-- 9|John Downs |matthew53@example.org |
11+
-- 4|John Green |davidtaylor@example.com |
12+
-- 1|Mike Cook |bryantteresa@example.org |
13+
-- 10|Emily Rose |juliehoward@example.net |
14+
15+
-- id|title |description |status_id|user_id|
16+
-- --+-------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+---------+-------+
17+
-- 1|Together herself hotel word may leader should. |Television they vote adult teach. Include life crime.¶Interesting have include Mr. Run program reality dark manager blood way along.¶Goal miss decide wall smile enjoy it. Talk interesting shake. | 1| 10|
18+
-- 3|Within young near huge help happy. |Sometimes second scientist production rest friend. Read door out will. Five even important house energy.¶Threat social ago ground important lose.¶Business build look. Off stay east we including this.| 1| 6|
19+
-- 5|Money toward image him ball gun. |The must PM then owner none number. Food expect with position.¶Stand land accept course include generation in yet. Truth probably just thing degree inside scientist some. | 1| 1|
20+
-- 8|Range great detail always. |Yeah become computer. Value think performance drive name. Especially toward agree walk moment firm American many. | 2| 7|
21+
-- 9|Radio side wish guy hit memory. |Organization window military development day. Them such protect kitchen employee film answer. Yeah natural its. | 1| 3|
22+
-- 11|Ready affect whatever develop discover. |Capital security quickly perhaps stand wife. Follow attorney form seven. Discover rock when.¶Despite mention else bar talk. Admit manage test which gun. Head follow have seem. | 3| 1|
23+
-- 13|My radio section enjoy technology. |Positive fish decade mission. Easy study paper. Show especially week mind could. | 1| 7|
24+
-- 14|Must score area real alone growth plan claim. |Bed difficult front voice. Statement can Congress painting sit.¶Vote wall it. Happen social glass small keep but keep cost. | 2| 7|
25+
-- 16|Reduce American whom bring marriage. |Major another study research. Hour health road last.¶Budget bad point consider. Agreement value will discussion course site want. Evidence hope team executive side southern hair. | 1| 7|
26+
-- 18|True cause once wall authority impact. |Ability that side mention well his. Present less especially drop season general bed.¶Difficult western old media. However response administration letter challenge participant. Radio focus each. | 1| 1|
27+
-- 20|Let spring also reveal every. Present get put. |Often might us organization coach world than. Newspaper least traditional case. Discover stand chair hospital head. | 1| 8|
28+
-- 7|Police cause participant. |Especially every sort relationship me inside. Thing government eight. Now state wind trouble hit then four.¶Speech off always authority. | 3| 10|
29+
-- 10|Difficult almost foreign hit carry past first. |Site long whatever. Peace enough effort. Finish rather wind watch ready.¶Particular four side address reflect degree enjoy. | 3| 10|
30+
-- 21|Wash the dish |Take it, wash it, dry it | 2| 4|
31+
-- 4|State than decide modern real add. | | 1| 10|
32+
-- 6|Different law expert. Think someone street above.| | 1| 7|

0 commit comments

Comments
 (0)