22
33from contextlib import asynccontextmanager
44from datetime import date # noqa: TC003
5- from typing import AsyncGenerator
5+ from typing import AsyncGenerator , List
66from uuid import UUID # noqa: TC003
77
88from fastapi import APIRouter , Depends , FastAPI , Request
99from pydantic import BaseModel as _BaseModel
10- from sqlalchemy import ForeignKey , select
10+ from sqlalchemy import ForeignKey
1111from sqlalchemy .ext .asyncio import AsyncSession # noqa: TC002
12- from sqlalchemy .orm import Mapped , mapped_column , relationship , selectinload
12+ from sqlalchemy .orm import Mapped , mapped_column , relationship
1313from typing_extensions import Annotated
1414
1515from advanced_alchemy .base import UUIDAuditBase , UUIDBase , metadata_registry
@@ -37,7 +37,7 @@ class AuthorModel(UUIDBase):
3737 __tablename__ = "author"
3838 name : Mapped [str ]
3939 dob : Mapped [date | None ]
40- books : Mapped [list [BookModel ]] = relationship (back_populates = "author" , lazy = "noload" )
40+ books : Mapped [List [BookModel ]] = relationship (back_populates = "author" , lazy = "noload" ) # noqa: UP006
4141
4242
4343# The `AuditBase` class includes the same UUID` based primary key (`id`) and 2
@@ -95,9 +95,7 @@ async def provide_authors_service(
9595 db_session : Annotated [AsyncSession , Depends (provide_db_session )],
9696) -> AsyncGenerator [AuthorService , None ]:
9797 """This provides the default Authors repository."""
98- async with AuthorService .new (
99- session = db_session ,
100- ) as service :
98+ async with AuthorService .new (session = db_session ) as service :
10199 yield service
102100
103101
@@ -107,10 +105,7 @@ async def provide_author_details_service(
107105 db_session : Annotated [AsyncSession , Depends (provide_db_session )],
108106) -> AsyncGenerator [AuthorService , None ]:
109107 """This provides a simple example demonstrating how to override the join options for the repository."""
110- async with AuthorService .new (
111- statement = select (AuthorModel ).options (selectinload (AuthorModel .books )),
112- session = db_session ,
113- ) as service :
108+ async with AuthorService .new (load = [AuthorModel .books ], session = db_session ) as service :
114109 yield service
115110
116111
0 commit comments