diff --git a/main_psycopg.py b/main_psycopg.py index 985bcaa..52aae77 100644 --- a/main_psycopg.py +++ b/main_psycopg.py @@ -2,18 +2,15 @@ import psycopg2 from dotenv import load_dotenv -from azure.identity import DefaultAzureCredential # Connect to the database load_dotenv(".env", override=True) DBUSER = os.environ["DBUSER"] DBPASS = os.environ["DBPASS"] -azure_credential = DefaultAzureCredential() -#DBPASS = azure_credential.get_token("https://ossrdbms-aad.database.windows.net") DBHOST = os.environ["DBHOST"] DBNAME = os.environ["DBNAME"] -conn = psycopg2.connect(database=DBNAME, user=DBUSER, password=DBPASS, host=DBHOST) +conn = psycopg2.connect(database=DBNAME, user=DBUSER, password=DBPASS, host=DBHOST, sslmode="require") cur = conn.cursor() cur.execute("DROP TABLE IF EXISTS restaurants") cur.execute("CREATE TABLE restaurants (id SERIAL PRIMARY KEY,name VARCHAR(255) NOT NULL)") diff --git a/main_sqlalchemy.py b/main_sqlalchemy.py index bee7917..56e7699 100644 --- a/main_sqlalchemy.py +++ b/main_sqlalchemy.py @@ -1,7 +1,7 @@ import os from dotenv import load_dotenv -from sqlalchemy import String, create_engine +from sqlalchemy import String, create_engine, select from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column @@ -14,6 +14,7 @@ class Restaurant(Base): __tablename__ = "restaurants" id: Mapped[int] = mapped_column(primary_key=True) name: Mapped[str] = mapped_column(String) + address: Mapped[str] = mapped_column(String, nullable=True) # Connect to the database @@ -36,3 +37,6 @@ class Restaurant(Base): for i in range(10): session.add(Restaurant(name=f"Cheese Shop #{i}")) session.commit() + + query = select(Restaurant) + results = session.execute(query) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index fe49132..50edce3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ psycopg2==2.9.7 python-dotenv==1.0.0 SQLAlchemy==2.0.20 faker==19.3.0 -azure-identity==1.14.0 \ No newline at end of file +pandas==2.0.3 \ No newline at end of file diff --git a/restaurants.csv b/restaurants.csv new file mode 100644 index 0000000..f329889 --- /dev/null +++ b/restaurants.csv @@ -0,0 +1,5 @@ +id,name,address +1,El Pollo Loco,123 Main St +2,Chipotle,456 Main St +3,McDonalds,789 Main St +4,In-N-Out,101 Main St