Skip to content

Commit

Permalink
More changes for stream
Browse files Browse the repository at this point in the history
  • Loading branch information
pamelafox committed Aug 23, 2023
1 parent f2c39cf commit d043531
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
5 changes: 1 addition & 4 deletions main_psycopg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
6 changes: 5 additions & 1 deletion main_sqlalchemy.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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
Expand All @@ -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)
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
pandas==2.0.3
5 changes: 5 additions & 0 deletions restaurants.csv
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d043531

Please sign in to comment.