# fastapi_sqlalchemy_async **Repository Path**: weni09/fastapi_sqlalchemy_async ## Basic Information - **Project Name**: fastapi_sqlalchemy_async - **Description**: FastAPI使用异步SQLAlchemy - **Primary Language**: Python - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 4 - **Created**: 2022-03-30 - **Last Updated**: 2022-03-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # fastapi_sqlalchemy_async #### 介绍 FastAPI使用异步SQLAlchemy #### 安装教程 1. 创建虚拟环境 Python3.8 2. pip install -r requirements.txt -i https://pypi.douban.com/simple #### 使用说明 1. python app.py 2. 访问 http://localhost:5000/docs #### 简介 使用异步,代码如下 ```python @router.get("/books") async def get_all_books(book_dal: BookDAL = Depends(get_book_dal)) -> List[Book]: return await book_dal.get_all_books() ``` ```python async def get_all_books(self) -> List[Book]: q = await self.db_session.execute(select(Book).order_by(Book.id)) return q.scalars().all() ``` #### 参考 https://towardsdatascience.com/build-an-async-python-service-with-fastapi-sqlalchemy-196d8792fa08