From 8a2fcfec7abe58d7c165eb0fddf0b93c31b4a9b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Santanch=C3=A8?= Date: Sun, 11 Aug 2024 18:32:14 -0300 Subject: [PATCH] update (full-stack/sqlmodel): explicit url building --- full-stack/2-sqlmodel/users_example_3_07.py | 9 ++++++++- full-stack/2-sqlmodel/users_example_3_10.py | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/full-stack/2-sqlmodel/users_example_3_07.py b/full-stack/2-sqlmodel/users_example_3_07.py index 3900e59..a23e33e 100644 --- a/full-stack/2-sqlmodel/users_example_3_07.py +++ b/full-stack/2-sqlmodel/users_example_3_07.py @@ -17,7 +17,14 @@ class Users(SQLModel, table=True): user_2 = Users(email_id="doriana@email.com", name="Doriana", birthday=parse_date("2024-03-05")) user_3 = Users(email_id="bonerges@email.com", name="Bonerges", birthday=parse_date("2024-05-01")) -engine = create_engine("postgresql://postgres:postgres@localhost:5431/test") +POSTGRES_USER = "postgres" +POSTGRES_PASSWORD = "postgres" +POSTGRES_SERVER = "localhost" +POSTGRES_PORT = "5431" +POSTGRES_DB = "test" +POSTGRES_URL = f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_SERVER}:{POSTGRES_PORT}/{POSTGRES_DB}" + +engine = create_engine(POSTGRES_URL) SQLModel.metadata.create_all(engine) diff --git a/full-stack/2-sqlmodel/users_example_3_10.py b/full-stack/2-sqlmodel/users_example_3_10.py index a8e2234..007f065 100644 --- a/full-stack/2-sqlmodel/users_example_3_10.py +++ b/full-stack/2-sqlmodel/users_example_3_10.py @@ -16,7 +16,14 @@ class Users(SQLModel, table=True): user_2 = Users(email_id="doriana@email.com", name="Doriana", birthday=parse_date("2024-03-05")) user_3 = Users(email_id="bonerges@email.com", name="Bonerges", birthday=parse_date("2024-05-01")) -engine = create_engine("postgresql://postgres:postgres@localhost:5431/test") +POSTGRES_USER = "postgres" +POSTGRES_PASSWORD = "postgres" +POSTGRES_SERVER = "localhost" +POSTGRES_PORT = "5431" +POSTGRES_DB = "test" +POSTGRES_URL = f"postgresql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{POSTGRES_SERVER}:{POSTGRES_PORT}/{POSTGRES_DB}" + +engine = create_engine(POSTGRES_URL) SQLModel.metadata.create_all(engine)