Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
13 changes: 13 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
python-dotenv = "*"
psycopg2-binary = "*"

[requires]
python_version = "3.8"
67 changes: 67 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added module1-introduction-to-sql/.DS_Store
Binary file not shown.
Empty file.
24 changes: 24 additions & 0 deletions module1-introduction-to-sql/rpg_db_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sqlite3


def connect_to_db(db_name='rpg_db.sqlite3'):
return sqlite3.connect(db_name)


def execute_query(cursor, query):
cursor.execute(query)
return cursor.fetchall()


GET_CHARACTERS = 'SELECT * FROM charactercreator_character;'


if __name__ == '__main__':
conn = connect_to_db()
curs = conn.cursor()
results = execute_query(curs, GET_CHARACTERS)
print(results)




Binary file added module1-introduction-to-sql/test_db.sqlite3
Binary file not shown.
31 changes: 31 additions & 0 deletions module2-sql-for-analysis/elephant_queries.py
Original file line number Diff line number Diff line change
@@ -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)