diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..f1bf68c7 Binary files /dev/null and b/.DS_Store differ diff --git a/Pipfile b/Pipfile new file mode 100644 index 00000000..53c32968 --- /dev/null +++ b/Pipfile @@ -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" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 00000000..e6c5fbb1 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,67 @@ +{ + "_meta": { + "hash": { + "sha256": "d2f7f8cb967ddbd2921f1a455faef3341e4ca3985397f61c4320aa4cf8e395fe" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.8" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "psycopg2-binary": { + "hashes": [ + "sha256:0deac2af1a587ae12836aa07970f5cb91964f05a7c6cdb69d8425ff4c15d4e2c", + "sha256:0e4dc3d5996760104746e6cfcdb519d9d2cd27c738296525d5867ea695774e67", + "sha256:11b9c0ebce097180129e422379b824ae21c8f2a6596b159c7659e2e5a00e1aa0", + "sha256:1fabed9ea2acc4efe4671b92c669a213db744d2af8a9fc5d69a8e9bc14b7a9db", + "sha256:2dac98e85565d5688e8ab7bdea5446674a83a3945a8f416ad0110018d1501b94", + "sha256:42ec1035841b389e8cc3692277a0bd81cdfe0b65d575a2c8862cec7a80e62e52", + "sha256:6a32f3a4cb2f6e1a0b15215f448e8ce2da192fd4ff35084d80d5e39da683e79b", + "sha256:7312e931b90fe14f925729cde58022f5d034241918a5c4f9797cac62f6b3a9dd", + "sha256:7d92a09b788cbb1aec325af5fcba9fed7203897bbd9269d5691bb1e3bce29550", + "sha256:833709a5c66ca52f1d21d41865a637223b368c0ee76ea54ca5bad6f2526c7679", + "sha256:8cd0fb36c7412996859cb4606a35969dd01f4ea34d9812a141cd920c3b18be77", + "sha256:950bc22bb56ee6ff142a2cb9ee980b571dd0912b0334aa3fe0fe3788d860bea2", + "sha256:a0c50db33c32594305b0ef9abc0cb7db13de7621d2cadf8392a1d9b3c437ef77", + "sha256:a0eb43a07386c3f1f1ebb4dc7aafb13f67188eab896e7397aa1ee95a9c884eb2", + "sha256:aaa4213c862f0ef00022751161df35804127b78adf4a2755b9f991a507e425fd", + "sha256:ac0c682111fbf404525dfc0f18a8b5f11be52657d4f96e9fcb75daf4f3984859", + "sha256:ad20d2eb875aaa1ea6d0f2916949f5c08a19c74d05b16ce6ebf6d24f2c9f75d1", + "sha256:b4afc542c0ac0db720cf516dd20c0846f71c248d2b3d21013aa0d4ef9c71ca25", + "sha256:b8a3715b3c4e604bcc94c90a825cd7f5635417453b253499664f784fc4da0152", + "sha256:ba28584e6bca48c59eecbf7efb1576ca214b47f05194646b081717fa628dfddf", + "sha256:ba381aec3a5dc29634f20692349d73f2d21f17653bda1decf0b52b11d694541f", + "sha256:bd1be66dde2b82f80afb9459fc618216753f67109b859a361cf7def5c7968729", + "sha256:c2507d796fca339c8fb03216364cca68d87e037c1f774977c8fc377627d01c71", + "sha256:cec7e622ebc545dbb4564e483dd20e4e404da17ae07e06f3e780b2dacd5cee66", + "sha256:d14b140a4439d816e3b1229a4a525df917d6ea22a0771a2a78332273fd9528a4", + "sha256:d1b4ab59e02d9008efe10ceabd0b31e79519da6fb67f7d8e8977118832d0f449", + "sha256:d5227b229005a696cc67676e24c214740efd90b148de5733419ac9aaba3773da", + "sha256:e1f57aa70d3f7cc6947fd88636a481638263ba04a742b4a37dd25c373e41491a", + "sha256:e74a55f6bad0e7d3968399deb50f61f4db1926acf4a6d83beaaa7df986f48b1c", + "sha256:e82aba2188b9ba309fd8e271702bd0d0fc9148ae3150532bbb474f4590039ffb", + "sha256:ee69dad2c7155756ad114c02db06002f4cded41132cc51378e57aad79cc8e4f4", + "sha256:f5ab93a2cb2d8338b1674be43b442a7f544a0971da062a5da774ed40587f18f5" + ], + "index": "pypi", + "version": "==2.8.6" + }, + "python-dotenv": { + "hashes": [ + "sha256:8c10c99a1b25d9a68058a1ad6f90381a62ba68230ca93966882a4dbc3bc9c33d", + "sha256:c10863aee750ad720f4f43436565e4c1698798d763b63234fb5021b6c616e423" + ], + "index": "pypi", + "version": "==0.14.0" + } + }, + "develop": {} +} diff --git a/module1-introduction-to-sql/.DS_Store b/module1-introduction-to-sql/.DS_Store new file mode 100644 index 00000000..1f8b9d5f Binary files /dev/null and b/module1-introduction-to-sql/.DS_Store differ diff --git a/module1-introduction-to-sql/rgp_db.sqlite3 b/module1-introduction-to-sql/rgp_db.sqlite3 new file mode 100644 index 00000000..e69de29b diff --git a/module1-introduction-to-sql/rpg_db_example.py b/module1-introduction-to-sql/rpg_db_example.py new file mode 100644 index 00000000..ba3a333f --- /dev/null +++ b/module1-introduction-to-sql/rpg_db_example.py @@ -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) + + + + diff --git a/module1-introduction-to-sql/test_db.sqlite3 b/module1-introduction-to-sql/test_db.sqlite3 new file mode 100644 index 00000000..638f5309 Binary files /dev/null and b/module1-introduction-to-sql/test_db.sqlite3 differ 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