Skip to content

Commit

Permalink
Azure changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pamelafox committed Aug 23, 2023
1 parent f06a836 commit f2c39cf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions .env.azure
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DBHOST=HOSTNAME.postgres.database.azure.com
DBUSER=USERNAME
DBPASS=ServerPassword
DBNAME=postgres
3 changes: 2 additions & 1 deletion main_psycopg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

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()
azure_credential = DefaultAzureCredential()
#DBPASS = azure_credential.get_token("https://ossrdbms-aad.database.windows.net")
DBHOST = os.environ["DBHOST"]
DBNAME = os.environ["DBNAME"]
Expand Down
9 changes: 6 additions & 3 deletions main_sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class Base(DeclarativeBase):

class Restaurant(Base):
__tablename__ = "restaurants"
id: Mapped[int] = mapped_column("id", String, primary_key=True)
name: Mapped[str] = mapped_column("name", String)
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String)


# Connect to the database
Expand All @@ -28,8 +28,11 @@ class Restaurant(Base):
engine = create_engine(DATABASE_URI, echo=True)

# Create tables in database
Base.metadata.drop_all(engine)
Base.metadata.create_all(engine)

# Insert data and issue queries
with Session(engine) as session:
pass
for i in range(10):
session.add(Restaurant(name=f"Cheese Shop #{i}"))
session.commit()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ psycopg2==2.9.7
python-dotenv==1.0.0
SQLAlchemy==2.0.20
faker==19.3.0
azure-identity==1.14.0

0 comments on commit f2c39cf

Please sign in to comment.