diff --git a/.env.example b/.env.example index 56e7c069252d39c8ba1059a0de2ae412634f5599..5b749851cc044dc5c9d53faa89dd4814a59d0696 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 d61a265ca889abfe20de8b39a82cfc5595178f10..6aed5e95bbf84aa6033c1e13f1693d42f3f566b5 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 a9f5493b0494ce61126f5380e9f8c496c94b7327..7dfdd9c74804cc689eb26be9dfa1530440fed11d 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