Create a table

This commit is contained in:
slashtechno 2024-06-04 09:19:12 -05:00
parent 062944b57a
commit ddf87eec2a
Signed by: slashtechno
GPG Key ID: 8EC1D9D9286C2B17
4 changed files with 105 additions and 6 deletions

View File

@ -4,8 +4,9 @@ services:
image: postgres:latest
ports:
- 5433:5432
volumes:
- ./db-data:/var/lib/postgresql/data
# Disabling persistence to allow for the program to be run multiple times
# volumes:
# - ./db-data:/var/lib/postgresql/data
# environment:
# POSTGRES_DB: "db"
# POSTGRES_PASSWORD: "dbpass"

View File

@ -5,7 +5,58 @@
groups = ["default"]
strategy = ["cross_platform", "inherit_metadata"]
lock_version = "4.4.1"
content_hash = "sha256:dec8a1404247926935fc662d04cb4195826a325ab9e8ff1461512f80878f104d"
content_hash = "sha256:2be337f3deba8cffea31cdbd43024c3db7bed53a688b484b32a3b92c27c530cf"
[[package]]
name = "asttokens"
version = "2.4.1"
summary = "Annotate AST trees with source code positions"
groups = ["default"]
dependencies = [
"six>=1.12.0",
]
files = [
{file = "asttokens-2.4.1-py2.py3-none-any.whl", hash = "sha256:051ed49c3dcae8913ea7cd08e46a606dba30b79993209636c4875bc1d637bc24"},
{file = "asttokens-2.4.1.tar.gz", hash = "sha256:b03869718ba9a6eb027e134bfdf69f38a236d681c83c160d510768af11254ba0"},
]
[[package]]
name = "colorama"
version = "0.4.6"
requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7"
summary = "Cross-platform colored terminal text."
groups = ["default"]
files = [
{file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"},
{file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"},
]
[[package]]
name = "executing"
version = "2.0.1"
requires_python = ">=3.5"
summary = "Get the currently executing AST node of a frame, and other information"
groups = ["default"]
files = [
{file = "executing-2.0.1-py2.py3-none-any.whl", hash = "sha256:eac49ca94516ccc753f9fb5ce82603156e590b27525a8bc32cce8ae302eb61bc"},
{file = "executing-2.0.1.tar.gz", hash = "sha256:35afe2ce3affba8ee97f2d69927fa823b08b472b7b994e36a52a964b93d16147"},
]
[[package]]
name = "icecream"
version = "2.1.3"
summary = "Never use print() to debug again; inspect variables, expressions, and program execution with a single, simple function call."
groups = ["default"]
dependencies = [
"asttokens>=2.0.1",
"colorama>=0.3.9",
"executing>=0.3.1",
"pygments>=2.2.0",
]
files = [
{file = "icecream-2.1.3-py2.py3-none-any.whl", hash = "sha256:757aec31ad4488b949bc4f499d18e6e5973c40cc4d4fc607229e78cfaec94c34"},
{file = "icecream-2.1.3.tar.gz", hash = "sha256:0aa4a7c3374ec36153a1d08f81e3080e83d8ac1eefd97d2f4fe9544e8f9b49de"},
]
[[package]]
name = "psycopg2-binary"
@ -29,6 +80,17 @@ files = [
{file = "psycopg2_binary-2.9.9-cp312-cp312-win_amd64.whl", hash = "sha256:81ff62668af011f9a48787564ab7eded4e9fb17a4a6a74af5ffa6a457400d2ab"},
]
[[package]]
name = "pygments"
version = "2.18.0"
requires_python = ">=3.8"
summary = "Pygments is a syntax highlighting package written in Python."
groups = ["default"]
files = [
{file = "pygments-2.18.0-py3-none-any.whl", hash = "sha256:b8e6aca0523f3ab76fee51799c488e38782ac06eafcf95e7ba832985c8e7b13a"},
{file = "pygments-2.18.0.tar.gz", hash = "sha256:786ff802f32e91311bff3889f6e9a86e81505fe99f2735bb6d60ae0c5004f199"},
]
[[package]]
name = "python-dotenv"
version = "1.0.1"
@ -39,3 +101,14 @@ files = [
{file = "python-dotenv-1.0.1.tar.gz", hash = "sha256:e324ee90a023d808f1959c46bcbc04446a10ced277783dc6ee09987c37ec10ca"},
{file = "python_dotenv-1.0.1-py3-none-any.whl", hash = "sha256:f7b63ef50f1b690dddf550d03497b66d609393b40b564ed0d674909a68ebf16a"},
]
[[package]]
name = "six"
version = "1.16.0"
requires_python = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*"
summary = "Python 2 and 3 compatibility utilities"
groups = ["default"]
files = [
{file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"},
{file = "six-1.16.0.tar.gz", hash = "sha256:1e61c37477a1626458e36f7b1d82aa5c9b094fa4802892072e49de9c60c4c926"},
]

View File

@ -8,6 +8,7 @@ authors = [
dependencies = [
"psycopg2-binary>=2.9.9",
"python-dotenv>=1.0.1",
"icecream>=2.1.3",
]
requires-python = ">=3.12"
readme = "README.md"

View File

@ -1,10 +1,33 @@
# https://www.freecodecamp.org/news/postgresql-in-python/
# https://www.datacamp.com/tutorial/tutorial-postgresql-python
import psycopg2
import dotenv
import os
import os
# from icecream import ic
def main():
cursor = connect().cursor()
print("Connecting to the PostgreSQL database...")
conn = connect()
cursor = conn.cursor()
print("Creating a table")
# SERIAL: auto-incrementing integer
# VARCHAR: variable-length character string
# (50) Set the maximum length of the course_name column to 50 characters.
# UNIQUE: ensure that all values in the course_name column are unique.
# NOT NULL: ensure that the course_name column cannot have NULL values.
# (100) Set the maximum length of the course_instructor column to 100 characters.
# (20) Set the maximum length of the topic column to 20 characters.
cursor.execute("""CREATE TABLE datacamp_courses(
course_id SERIAL PRIMARY KEY,
course_name VARCHAR (50) UNIQUE NOT NULL,
course_instructor VARCHAR (100) NOT NULL,
topic VARCHAR (20) NOT NULL);
""")
print("Committing the table to the database...")
print("Closing the connection adn the cursor...")
cursor.close()
conn.close()
# cursor.execute("SELECT * FROM DB_table WHERE id = 1")
@ -19,4 +42,5 @@ def connect():
)
return conn
main()
if __name__ == "__main__":
main()