fastapi-listing icon indicating copy to clipboard operation
fastapi-listing copied to clipboard

Async Session

Open elektracodes opened this issue 11 months ago • 3 comments

Hello!

Can this work with AsyncSession? I am trying to work with the examples but I cannot seem to be able to overwrite the sorter.

I get this error

fastapi_listing/sorter/page_sorter.py
File "/opt/pysetup/.venv/lib/python3.11/site-packages/fastapi_listing/sorter/page_sorter.py", line 20, in sort_dsc_util
  query = query.order_by(inst_field.desc())
AttributeError: 'coroutine' object has no attribute 'order_by'

I have overwrite the get_default_read to work with async, but I cannot see how to do that in the page_sorter.

class VideoDao(GenericDao):
    def __init__(self, db: AsyncSession) -> None:
        super().__init__(db)

    name = "videoresponse"
    model = Videos

    async def get_default_read(self, fields_to_read: Optional[list]):
        query = await self.db.query(Videos)
        return query

elektracodes avatar Mar 12 '24 23:03 elektracodes