I'm a bit confused regarding asynchrony in FastAPI. Supposedly, I want to communicate with a database asynchronously. I have the following function that I will use later in some endpoint to write a record:
async def post(payload: SummaryPayloadSchema) -> int:
summary = TextSummary(
url=payload.url,
summary="dummy summary",
)
await summary.save()
return summary.id
But what I want is that while this is happening to be able get some record from the database as well. In other words, execute the previous coroutine asynchronously with another to read some data. How can I achieve that? Should I implement some technology like celery to execute both tasks asynchronously or can it only be done with FastAPI? And in the event that in the same endpoint you want to go asynchronously also obtaining other records, does the same apply? Thank you very much, I hope you can help me!