diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ff44102..b1b6ab5 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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", diff --git a/get_pg_pass.py b/get_pg_pass.py new file mode 100644 index 0000000..e6a5303 --- /dev/null +++ b/get_pg_pass.py @@ -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 \ No newline at end of file diff --git a/main_psycopg.py b/main_psycopg.py index 33b75c2..7ce3736 100644 --- a/main_psycopg.py +++ b/main_psycopg.py @@ -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() \ No newline at end of file +cur.close() diff --git a/main_sqlalchemy.py b/main_sqlalchemy.py index 960090c..0511bc6 100644 --- a/main_sqlalchemy.py +++ b/main_sqlalchemy.py @@ -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 @@ -21,7 +17,7 @@ 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"] @@ -29,7 +25,6 @@ class Restaurant(Base): 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 @@ -38,4 +33,3 @@ class Restaurant(Base): # Insert data and issue queries with Session(engine) as session: pass - diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..206b434 --- /dev/null +++ b/pyproject.toml @@ -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"] \ No newline at end of file