Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document relevant asyncio notes for SQLAlchemy #26

Open
3 tasks
devraj opened this issue Jul 31, 2022 · 0 comments
Open
3 tasks

Document relevant asyncio notes for SQLAlchemy #26

devraj opened this issue Jul 31, 2022 · 0 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@devraj
Copy link
Member

devraj commented Jul 31, 2022

When using asyncio - queries etc use the new 2.0 query pattern e.g

    @classmethod
    async def get_active_for_facility(cls, async_db_session, facility_id):
        query = select(cls).options(selectinload(cls.products)).\
            where(cls.facility_id == facility_id).\
            where(cls.active == True)
        results = await async_db_session.execute(query)
        (result,) =  results.scalars().all()
        return result

which also means using statements like select(cls).options(selectinload(cls.products)) to load the children. This is required when we are trying to include these objects as part of the API results.

While SQLAlchemy has extensive documentation about this we should extract our some useful tips and tricks to speed up the learning process, current hit list

@devraj devraj self-assigned this Jul 31, 2022
@devraj devraj added the documentation Improvements or additions to documentation label Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant