Skip to content

Commit

Permalink
Changes in prep for stream
Browse files Browse the repository at this point in the history
  • Loading branch information
pamelafox committed Aug 23, 2023
1 parent bf9c6d9 commit f06a836
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 17 deletions.
5 changes: 2 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": false,
"[python]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll": true
}
},
"editor.defaultFormatter": "ms-python.black-formatter"
},
"python.formatting.provider": "black",
"sqltools.connections": [
{
"name": "Local database",
Expand Down
9 changes: 9 additions & 0 deletions get_pg_pass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import os

from azure.identity import DefaultAzureCredential


def get_conn():
azure_credential = DefaultAzureCredential()
token = azure_credential.get_token("https://ossrdbms-aad.database.windows.net")
return token.token
12 changes: 7 additions & 5 deletions main_psycopg.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import os


from dotenv import load_dotenv
import psycopg2

from dotenv import load_dotenv

# Connect to the database
load_dotenv(".env")
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)
cur = conn.cursor()
cur.execute("DROP TABLE IF EXISTS restaurants")
cur.execute("CREATE TABLE restaurants (id SERIAL PRIMARY KEY,name VARCHAR(255) NOT NULL)")
cur.execute("INSERT INTO restaurants (id, name) VALUES ('3', 'test')")
conn.commit()
cur.close()
cur.close()
12 changes: 3 additions & 9 deletions main_sqlalchemy.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import os


from dotenv import load_dotenv
from sqlalchemy import String
from sqlalchemy.orm import Session, Mapped
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import mapped_column
from sqlalchemy import create_engine
from sqlalchemy import String, create_engine
from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column


# Define the models
Expand All @@ -21,15 +17,14 @@ class Restaurant(Base):


# Connect to the database
load_dotenv(".env")
load_dotenv(".env", override=True)
DBUSER = os.environ["DBUSER"]
DBPASS = os.environ["DBPASS"]
DBHOST = os.environ["DBHOST"]
DBNAME = os.environ["DBNAME"]
DATABASE_URI = f"postgresql://{DBUSER}:{DBPASS}@{DBHOST}/{DBNAME}"
if DBHOST != "localhost":
DATABASE_URI += "?sslmode=require"

engine = create_engine(DATABASE_URI, echo=True)

# Create tables in database
Expand All @@ -38,4 +33,3 @@ class Restaurant(Base):
# Insert data and issue queries
with Session(engine) as session:
pass

10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tool.ruff]
line-length = 120
target-version = "py311"
select = ["E", "F", "I", "UP"]
ignore = ["D203"]
show-source = true

[tool.black]
line-length = 120
target-version = ["py311"]

0 comments on commit f06a836

Please sign in to comment.