anomaly / anomaly/lab-python-server

Document relevant asyncio notes for SQLAlchemy

オープン
#26 コメント 0 件 リアクション 0 件 担当者 1 名 @devraj が担当を希望しています GitHub で見る
documentation
主要言語
Python
スター
16
フォーク
4
PR マージ指標
30日以内にマージされた PR はありません

説明

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

```python
@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](https://docs.sqlalchemy.org/en/14/orm/extensions/asyncio.html) we should extract our some useful tips and tricks to speed up the learning process, current hit list

- [ ] Defining [relationships for eager loading](https://leontrolski.github.io/sqlalchemy-relationships.html)
- [ ] Querying many or single objects
- [ ] Loading objects multiple levels deep

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。