chore: rework DB module (#324)

This commit is contained in:
d3vyce
2026-06-25 21:11:50 +02:00
committed by GitHub
parent 22f307d0fc
commit 9698a0743b
23 changed files with 1662 additions and 931 deletions
@@ -2,8 +2,10 @@ from fastapi import FastAPI
from fastapi_toolsets.exceptions import init_exceptions_handlers
from .db import db
from .routes import router
app = FastAPI()
db.install(app=app)
init_exceptions_handlers(app=app)
app.include_router(router=router)
+5 -8
View File
@@ -1,17 +1,14 @@
from typing import Annotated
from fastapi import Depends
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker, create_async_engine
from sqlalchemy.ext.asyncio import AsyncSession
from fastapi_toolsets.db import create_db_context, create_db_dependency
from fastapi_toolsets.db import Database
DATABASE_URL = "postgresql+asyncpg://postgres:postgres@localhost:5432/postgres"
engine = create_async_engine(url=DATABASE_URL, future=True)
async_session_maker = async_sessionmaker(bind=engine, expire_on_commit=False)
db = Database(url=DATABASE_URL)
get_db = create_db_dependency(session_maker=async_session_maker)
get_db_context = create_db_context(session_maker=async_session_maker)
get_db = db
SessionDep = Annotated[AsyncSession, Depends(get_db)]
SessionDep = Annotated[AsyncSession, Depends(db)]