Skip to content

Commit 1832938

Browse files
authored
feat: add local db for debug
1 parent c4a4dd6 commit 1832938

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ DEBUG=True
33
PROJECT_NAME="My app"
44
VERSION="1.0.0"
55

6-
DATABASE_URL="postgresql+asyncpg://postgres:postgres@localhost:5432/valory"
6+
DATABASE_URL="postgresql+asyncpg://postgres:postgres@localhost:5432/valory"
7+
DEGUB_DATABASE_URL="sqlite+aiosqlite:///sqlite.db"

backend/app/db/session.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
from sqlmodel import SQLModel
44
from app import settings
55

6-
engine = create_async_engine(settings.DATABASE_URL, echo=True, future=True)
6+
if settings.DEBUG:
7+
engine = create_async_engine(settings.DEGUB_DATABASE_URL, echo=True, future=True)
8+
else:
9+
engine = create_async_engine(settings.DATABASE_URL, echo=True, future=True)
710

811
AsyncSessionLocal = sessionmaker(
912
bind=engine,

backend/app/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ def str_to_bool(value: str) -> bool:
2020
PROJECT_NAME = environ.get('PROJECT_NAME')
2121
VERSION = environ.get('VERSION')
2222

23-
DATABASE_URL = environ.get('DATABASE_URL')
23+
DATABASE_URL = environ.get('DATABASE_URL')
24+
DEGUB_DATABASE_URL = environ.get('DEGUB_DATABASE_URL')

backend/main.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ async def lifespan(app: FastAPI):
3030
allow_headers=["*"],
3131
)
3232

33-
app.include_router(api_router, prefix="/api/v1")
33+
app.include_router(api_router, prefix="/api/")
3434

35-
@app.get("/")
36-
async def read_root():
37-
return {"message": "Welcome to the API!"}
35+
if __name__ == "__main__":
36+
uvicorn.run(app="main:app", reload=True)

0 commit comments

Comments
 (0)