diff --git a/.env.azure b/.env.azure new file mode 100644 index 0000000..fa32ae6 --- /dev/null +++ b/.env.azure @@ -0,0 +1,4 @@ +DBHOST=HOSTNAME.postgres.database.azure.com +DBUSER=USERNAME +DBPASS=ServerPassword +DBNAME=postgres diff --git a/main_psycopg.py b/main_psycopg.py index 7ce3736..985bcaa 100644 --- a/main_psycopg.py +++ b/main_psycopg.py @@ -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"] diff --git a/main_sqlalchemy.py b/main_sqlalchemy.py index 0511bc6..bee7917 100644 --- a/main_sqlalchemy.py +++ b/main_sqlalchemy.py @@ -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 @@ -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() diff --git a/requirements.txt b/requirements.txt index 5a94f51..fe49132 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 \ No newline at end of file