From f3dfd02c279923af4e469b827db3ef334facd303 Mon Sep 17 00:00:00 2001 From: duyanhehe <duyanhex@gmail.com> Date: Thu, 6 Mar 2025 11:56:15 +0700 Subject: [PATCH] changes to env and config --- .env.example | 18 +++++++----------- app/core/config.py | 13 ++++++++++--- requirements.txt | 1 - 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/.env.example b/.env.example index 56e7c06..5b74985 100644 --- a/.env.example +++ b/.env.example @@ -1,11 +1,7 @@ -# Copy this file to .env - -APP_NAME = Shopping App -# Change to your own database -DATABASE_URL = mysql+pymysql://your_user:your_password@localhost/shopping # This template use mysql -# change your_user to your mysql username -# change your_password to your mysql password -# change localhost to 127.0.0.1 if youre running on local - -SECRET_KEY = your_secret_key -DEBUG = True # Only True or False \ No newline at end of file +APP_NAME="Shopping App" +DATABASE_USERNAME="your_mysql_username" +DATABASE_PASSWORD="your_mysql_password" +DATABASE_HOST="127.0.0.1" +DATABASE_NAME="shopping" +SECRET_KEY="your_secret_key" +DEBUG=True diff --git a/app/core/config.py b/app/core/config.py index d61a265..6aed5e9 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -4,14 +4,21 @@ from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): app_name: str = "Shopping App" - database_url: str # Ensure lowercase to match the .env key + database_username: str + database_password: str + database_host: str + database_name: str secret_key: str - debug: bool = True # Lowercase to match Python conventions + debug: bool = True + + @property + def database_url(self) -> str: + return f"mysql+pymysql://{self.database_username}:{self.database_password}@{self.database_host}/{self.database_name}" model_config = SettingsConfigDict( env_file=str(Path(__file__).resolve().parent.parent / ".env"), env_file_encoding="utf-8", - case_sensitive=False, # Allows case-insensitive environment variable keys + case_sensitive=False, ) diff --git a/requirements.txt b/requirements.txt index a9f5493..7dfdd9c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -49,6 +49,5 @@ typing_extensions==4.12.2 ujson==5.10.0 urllib3==2.3.0 uvicorn==0.34.0 -uvloop==0.21.0 watchfiles==1.0.4 websockets==15.0 -- GitLab