From 9b85c705577557d8ad4b6f3aa6b7dcdc0ea897f9 Mon Sep 17 00:00:00 2001 From: Mahmoud Fansha Date: Wed, 9 Sep 2020 23:43:20 -0700 Subject: [PATCH] elephant queries using python queries --- .DS_Store | Bin 0 -> 6148 bytes Pipfile | 13 ++++ Pipfile.lock | 67 ++++++++++++++++++ module1-introduction-to-sql/.DS_Store | Bin 0 -> 6148 bytes module1-introduction-to-sql/rgp_db.sqlite3 | 0 module1-introduction-to-sql/rpg_db_example.py | 24 +++++++ module1-introduction-to-sql/test_db.sqlite3 | Bin 0 -> 8192 bytes module2-sql-for-analysis/elephant_queries.py | 31 ++++++++ 8 files changed, 135 insertions(+) create mode 100644 .DS_Store create mode 100644 Pipfile create mode 100644 Pipfile.lock create mode 100644 module1-introduction-to-sql/.DS_Store create mode 100644 module1-introduction-to-sql/rgp_db.sqlite3 create mode 100644 module1-introduction-to-sql/rpg_db_example.py create mode 100644 module1-introduction-to-sql/test_db.sqlite3 create mode 100644 module2-sql-for-analysis/elephant_queries.py diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..f1bf68c7e3d3ce019ebb64ec341deb597950b76b GIT binary patch literal 6148 zcmeHK&5ja55U$=ucfc4qm@J8xxtMqWg#~vH#spb7kf^ykRW2X z_z?O4CO(Q!;Dh)8`c-%DhJp2B%!ZgQ(*0F;byf9L^$$%%qBZhsL`5R9P#ALsROb-O zxvbEJ?qQ*jHXf5hoo*QSyl`c-=`ay65m>hf@ZQ~`ht#Eg>d?aejXg;CSh$CB>z5>O zL^o(aG5Iv2kor`k3I!BVN<-b-10R5oAW4B0O6VQp$h`t9FX^~TAG7fP$&y^}CV z(rWdG*x1Zny1Zps1*>qi@Y*?!$4=^|qom~yUvle-n;v_be-_8#8Si?}gZ}uSczr*P zQa6bDL#Z72eGGZ^B8dEW+=@q$pGZ575?EH=${!R<(`o%~qipZ&)@NmVy0=#?+l~6} zY?imSZ`SU24+oR?(+{(cpJfrZ+CT36P8s%C~J0ww|%905KbY!t?(#<@ay zbfA(?0ALQ?lECwy2G+4PHZ{%_LIM&>6{u8&eqsovj(%H@YigV;RO%%3<3niALcdUi z^bY&B98RLC(9|XZCIZ*n1%5!G4Qh+hFG?%Ape+0qBz_-10N&Xa zO45Ru5TLurevadJ=X+7?7=UTa<0GI3pv)pzsaq6L$c5Ms50L!`iwYabcs4bFV8Vgg_-X_ zw3)H~PTsEtcKvHM4spwOKWA~=0aI#THXBUI@2xAz w$zB_i+L~= wb<>jOCiwo%D{`wAkK+miAOHafKmY;|fB*y_009U<00RFk(C5yG_k|w60i`M)UH||9 literal 0 HcmV?d00001 diff --git a/module2-sql-for-analysis/elephant_queries.py b/module2-sql-for-analysis/elephant_queries.py new file mode 100644 index 00000000..79820166 --- /dev/null +++ b/module2-sql-for-analysis/elephant_queries.py @@ -0,0 +1,31 @@ +import psycopg2 +import os +from dotenv import load_dotenv + + +load_dotenv() #> LOADS CONTENTS OF THE .env FILE INTO THE SCRIPTS EVNIRMONT + +DB_NAME = os.getenv("DB_NAME") +DB_USER = os.getenv("DB_USER") +DB_PASSWORD = os.getenv("DB_PASSWORD") +DB_HOST = os.getenv("DB_HOST") + +print(DB_NAME, DB_USER, DB_PASSWORD, DB_HOST) + + + +### Connect to ElephantSQL-hosted PostgreSQL +connection = psycopg2.connect(dbname=DB_NAME, user=DB_USER, password=DB_PASSWORD, host=DB_HOST) +print("CONNECTION", connection) + +### A "cursor", a structure to iterate over db records to perform queries +cursor = connection.cursor() +print("CURSOR", cursor) + +### An example query +cursor.execute('SELECT * from test_table;') + + +### Note - nothing happened yet! We need to actually *fetch* from the cursor +result = cursor.fetchall() +print(result) \ No newline at end of file